Java的主要工作是通過程式語言來製作網際網路頁面、製作動態效果以及網站等技術,現在網上關於這方面的教程有很多。下面是小編整理的關於Java基礎筆試題,希望大家認真閱讀!
1、 編寫程式,實現1到100之間整數的累加並輸出運算結果。
public class a
{
public static void main(String[] args)
{
int i,s=0;
for(i=1;i<=100;i++)
{
s=s+i;
}
tln("1到100的累加和是"+s);
}}
2、編寫程式,計算1~100中奇數的累加和並輸出。
public class a
{
public static void main(String[] args)
{
int i,s=0;
for(i=1;i<=100;i++)
{
if(i%2!=0)
s=s+i;
}
tln("1到100的奇數累加和是"+s);
}}
3、編寫程式,計算1~100中偶數的`累加和並輸出。
public class a
{
public static void main(String[] args)
{
int i,s=0;
for(i=1;i<=100;i++)
{
if(i%2==0)
s=s+i;
}
tln("1到100的偶數累加和是"+s);
}}
4、比較兩個數的大小,找出其中的最大數並輸出。
import .*;
public class ka
{ public static void main(String[] args) throws IOException
{
float? x,y,m;
m=0;
InputStreamReader readerx=new InputStreamReader();
BufferedReader inputx=new BufferedReader(readerx);
tln("請輸入x:");
String tempx=Line();
x = eFloat(tempx);
InputStreamReader readery=new InputStreamReader();
BufferedReader inputy=new BufferedReader(readery);
tln("請輸入y:");
String tempy=Line();
y= eFloat(tempy);
if(x>y)
{
m=x;
}else
{
m=y;
}
tln("最大數為"+m);
}
}
5、比較兩個數的大小,找出其中的最小數並輸出。
import .*;
public class ka
{ public static void main(String[] args) throws IOException
{
float? x,y,m;
m=0;
InputStreamReader readerx=new InputStreamReader();
BufferedReader inputx=new BufferedReader(readerx);
tln("請輸入x:");
String tempx=Line();
x = eFloat(tempx);
InputStreamReader readery=new InputStreamReader();
BufferedReader inputy=new BufferedReader(readery);
tln("請輸入y:");
String tempy=Line();
y= eFloat(tempy);
if(x{
m=x;
}else
{
m=y;
}
tln("最小數為"+m);
}
}
6、編寫一個Java程式,判斷某年份是否為閏年。
import .*;
public class testa
{
public static void main(String[] args) throws IOException
{
float? x;
InputStreamReader reader=new InputStreamReader();
BufferedReader input=new BufferedReader(reader);
tln("請輸入x:");
String temp=Line();
x =eFloat(temp);
if(x@0==0)
{
tln(+x+"是閏年");
}
else
if(x%4==0)
{
tln(+x+"是閏年");
}
else{ tln(+x+"不是閏年");}
}
}
7、比較兩個數的大小,找出其中的最大數和最小數並輸出。
import .*;
public class ka
{ public static void main(String[] args) throws IOException
{
float? x,y;
InputStreamReader readerx=new InputStreamReader();
BufferedReader inputx=new BufferedReader(readerx);
tln("請輸入x:");
String tempx=Line();
x = eFloat(tempx);
InputStreamReader readery=new InputStreamReader();
BufferedReader inputy=new BufferedReader(readery);
tln("請輸入y:");
String tempy=Line();
y= eFloat(tempy);
if(x{
tln("最小數為"+x);
tln("最大數為"+y);
}else
{
tln("最小數為"+y);
tln("最大數為"+x);
}
}
}
8、比較兩個數的大小,找出其中的最大數和最小數,並輸出最大數和最小數之差。
import .*;
public class ka
{ public static void main(String[] args) throws IOException
{
float? x,y,m;
InputStreamReader readerx=new InputStreamReader();
BufferedReader inputx=new BufferedReader(readerx);
tln("請輸入x:");
String tempx=Line();
x = eFloat(tempx);
InputStreamReader readery=new InputStreamReader();
BufferedReader inputy=new BufferedReader(readery);
tln("請輸入y:");
String tempy=Line();
y= eFloat(tempy);
if(x{
tln("最小數為"+x);
tln("最大數為"+y);