计算机二级考试Java模拟试题及答案2022_第1页
计算机二级考试Java模拟试题及答案2022_第2页
计算机二级考试Java模拟试题及答案2022_第3页
计算机二级考试Java模拟试题及答案2022_第4页
计算机二级考试Java模拟试题及答案2022_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

本文格式为Word版,下载可任意编辑——计算机二级考试Java模拟试题及答案2022计算机二级考试Java模拟试题及答案2022

不积跬步,何以至千里。试题的规律都是从一点一滴积累而来。下面是我整理的计算机二级考试Java模拟试题及答案,接待练习!

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

x?x=0

y=

-x?x0

importjava.io.*;

publicclasstesta

publicstaticvoidmainString[]argsthrowsIOException

float?x,y;

InputStreamReaderreader=newInputStreamReaderSystem.in;

BufferedReaderinput=newBufferedReaderreader;

System.out.println请输入x:;

Stringtemp=input.readLine;

x=Float.parseFloattemp;

ifx=0

y=x;

else

y=-x;

System.out.printlny=+y;

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

importjava.io.*;

publicclasstesta

publicstaticvoidmainString[]argsthrowsIOException

intx;

InputStreamReaderreader=newInputStreamReaderSystem.in;

BufferedReaderinput=newBufferedReaderreader;

System.out.println请输入x:;

Stringtemp=input.readLine;

x=Float.parseFloattemp;

ifx=18

System.out.println成年人;

ifx18

System.out.println未成年;

3、判断2022的奇偶性,并举行输出。

publicclasstest

publicstaticvoidmainString[]args

intx;

x=2022;

ifx%2==0

System.out.println+x+是偶数;

else

System.out.println+x+不是偶数;

4、对比两个数的`大小,找出其中的最大数并输出。

importjava.io.*;

publicclasska

publicstaticvoidmainString[]argsthrowsIOException

float?x,y,m;

m=0;

InputStreamReaderreaderx=newInputStreamReaderSystem.in;

BufferedReaderinputx=newBufferedReaderreaderx;

System.out.println请输入x:;

Stringtempx=inputx.readLine;

x=Float.parseFloattempx;

InputStreamReaderreadery=newInputStreamReaderSystem.in;

BufferedReaderinputy=newBufferedReaderreadery;

System.out.println请输入y:;

Stringtempy=inputy.readLine;

y=Float.parseFloattempy;

ifxy

m=x;

else

m=y;

System.out.println最大数为+m;

5、对比两个数的大小,找出其中的最小数并输出。

importjava.io.*;

publicclasska

publicstaticvoidmainString[]argsthrowsIOException

float?x,y,m;

m=0;

InputStreamReaderreaderx=newInputStreamReaderSystem.in;

BufferedReaderinputx=newBufferedReaderreaderx;

System.out.println请输入x:;

Stringtempx=inputx.readLine;

x=Float.parseFloattempx;

InputStreamReaderreadery=newInputStreamReaderSystem.in;

BufferedReaderinputy=newBufferedReaderreadery;

System.out.println请输入y:;

Stringtempy=inputy.readLine;

y=Float.parseFloattempy;

ifx

m=x;

else

m=y;

System.out.println最小数为+m;

6、编写一个Java程序,判断某年份是否为闰年。

importjava.io.*;

publicclasstesta

publicstaticvoidmainString[]argsthrowsIOException

float?x;

InputStreamReaderreader=newInputStreamReaderSystem.in;

BufferedReaderinput=newBufferedReaderreader;

System.out.println请输入x:;

Stringtemp=input.readLine;

x=Float.parseFloattemp;

ifx@0==0

System.out.println+x+是闰年;

else

ifx%4==0

System.out.println+x+是闰年;

elseSystem.out.println+x+不是闰年;

7、对比两个数的大小,找出其中的最大数和最小数并输出。

importjava.io.*;

publicclasska

publicstaticvoidmainString[]argsthrowsIOException

float?x,y;

InputStreamReaderreaderx=newInputStreamReaderSystem.in;

BufferedReaderinputx=newBufferedReaderreaderx;

System.out.println请输入x:;

Stringtempx=inputx.readLine;

x=Float.parseFloattempx;

InputStreamReaderreadery=newInputStreamReaderSystem.in;

BufferedReaderinputy=newBufferedReaderreadery;

System.out.println请输入y:;

Stringtempy=inputy.readLine;

y=Float.parseFloattempy;

ifx

System.out.println最小数为+x;

System.out.println最大数为+y;

else

System.out.println最小数为+y;

System.out.println最大数为+x;

8、对比两个数的大小,找出其中的最大数和最小数,并输出最大数和最小数之差。

importjava.io.*;

publicclasska

publicstaticvoidmainString[]argsthrowsIOException

float?x,y,m;

InputStreamReaderreaderx=newInputStreamReaderSystem.in;

BufferedReaderinputx=newBufferedReaderreaderx;

System.out.println请输入x:;

Stringtempx=inputx.readLine;

x=Float.parseFloattempx;

InputStreamReaderreadery=newInputStreamReaderSystem.in;

BufferedReaderinputy=newBufferedReaderreadery;

System.out.println请输入y:;

Stringtempy=inputy.readLine;

y=Float.parseFloattempy;

ifx

System.out.println最小数为+x;

System.out.println最大数为+y;

m=y-x;

System.out.println最大数与最小数之差为+m;

else

System.out.println最小数为+y;

System.out.println最大数为+x;

m=x-y;

System.out.println最大数与最小数之差为+m;

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

x?x0

y=????0?x=0

-x?x0

importjava.io.*;

publicclasstesta

publicstaticvoidmainString[]argsthrowsIOException

float?x,y;

y=0;

InputStreamReaderreader=newInputStreamReaderSystem.in;

BufferedReaderinput=newBufferedReaderreader;

System.out.println请输入x:;

Stringtemp=input.readLine;

x=Float.parseFloattemp;

ifx0

y=x;

ifx==0

y=0;

ifx0

y=-x;

System.out.printlny=+y;

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

x-1?x1

y=????0?-1x1

x+10?x-1

importjava.io.*;

publicclasstesta

publicstaticvoidmainString[]argsthrowsIOException

float?x,y;

y=0;

InputStreamReaderreader=ne

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论