计算机语言Java考试模拟试题附答案

科学的未来只能是属于勤奋而又谦虚的年轻一代!以下是小编为大家搜索整理的计算机语言Java考试模拟试题附答案,希望能给大家带来帮助!更多精彩内容请及时关注我们应届毕业生考试网!

计算机语言Java考试模拟试题附答案

  1、编写程序,计算下列分段函数的值。

x? (x>=0)

y=

-x? (x<0)

import .*;

public class testa

{ public static void main(String[] args) throws IOException

{

float? x,y;

InputStreamReader reader=new InputStreamReader();

BufferedReader input=new BufferedReader(reader);

tln("请输入x:");

String temp=Line();

x = eFloat(temp);

if(x>=0)

{

y=x;

}else

{

y=-x;

}

tln("y="+y);

}

}

2、根据年龄,判断某人是否为成年。

import .*;

public class testa

{

public static void main(String[] args) throws IOException

{

int x;

InputStreamReader reader=new InputStreamReader();

BufferedReader input=new BufferedReader(reader);

tln("请输入x:");

String temp=Line();

x = eFloat(temp);

if(x>=18)

{

tln("成年人");

}

if(x<18)

{

tln("未成年");

}

}

}

3、判断2020的.奇偶性,并进行输出。

public class test

{

public static void main(String[] args)

{

int x;

x=2020;

if(x%2==0)

tln(+x+"是偶数");

else

tln(+x+"不是偶数");

}

}

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