2017年Java基础笔试题

Java的主要工作是通过编程语言来制作互联网页面、制作动态效果以及网站等技术,现在网上关于这方面的教程有很多。下面是小编整理的关于Java基础笔试题,希望大家认真阅读!

2017年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);