欢迎来到金达范文网!

9月计算机二级考试JAVA考试题及答案(2023年)

时间:2023-02-11 10:20:05 来源:金达范文网

2023年下半年计算机二级考试正在备考中。你知道计算机二级考试JAVA科目都考哪些知识吗?为了方便考生备考计算机二级考试JAVA科目。下面是小编为大家带来的计算机二级考试JAVA考试题,欢迎阅读。下面是小编为大家整理的9月计算机二级考试JAVA考试题及答案(2023年),供大家参考。

9月计算机二级考试JAVA考试题及答案(2023年)

  2020年下半年计算机二级考试正在备考中。你知道计算机二级考试JAVA科目都考哪些知识吗?为了方便考生备考计算机二级考试JAVA 科目。下面是小编为大家带来的计算机二级考试JAVA考试题,欢迎阅读。

    考试题一:

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

  x? x>=0

  y=

  -x? x<0

  import java.io.*;

  public class testa

  public static void mainString[] args throws IOException

  float? x,y;

  InputStreamReader reader=new InputStreamReaderSystem.in;

  BufferedReader input=new BufferedReaderreader;

  System.out.println"请输入x:";

  String temp=input.readLine;

  x = Float.parseFloattemp;

  ifx>=0

  y=x;

  else

  y=-x;

  System.out.println"y="+y;

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

  import java.io.*;

  public class testa

  public static void mainString[] args throws IOException

  int x;

  InputStreamReader reader=new InputStreamReaderSystem.in;

  BufferedReader input=new BufferedReaderreader;

  System.out.println"请输入x:";

  String temp=input.readLine;

  x = Float.parseFloattemp;

  ifx>=18

  System.out.println"成年人";

  ifx<18

  System.out.println"未成年";

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

  public class test

  public static void mainString[] args

  int x;

  x=2020;

  ifx%2==0

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

  else

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

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

  import java.io.*;

  public class ka

  public static void mainString[] args throws IOException

  float? x,y,m;

  m=0;

  InputStreamReader readerx=new InputStreamReaderSystem.in;

  BufferedReader inputx=new BufferedReaderreaderx;

  System.out.println"请输入x:";

  String tempx=inputx.readLine;

  x = Float.parseFloattempx;

  InputStreamReader readery=new InputStreamReaderSystem.in;

  BufferedReader inputy=new BufferedReaderreadery;

  System.out.println"请输入y:";

  String tempy=inputy.readLine;

  y= Float.parseFloattempy;

  ifx>y

  m=x;

  else

  m=y;

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

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

  import java.io.*;

  public class ka

  public static void mainString[] args throws IOException

  float? x,y,m;

  m=0;

  InputStreamReader readerx=new InputStreamReaderSystem.in;

  BufferedReader inputx=new BufferedReaderreaderx;

  System.out.println"请输入x:";

  String tempx=inputx.readLine;

  x = Float.parseFloattempx;

  InputStreamReader readery=new InputStreamReaderSystem.in;

  BufferedReader inputy=new BufferedReaderreadery;

  System.out.println"请输入y:";

  String tempy=inputy.readLine;

  y= Float.parseFloattempy;

  ifx

  m=x;

  else

  m=y;

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

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

  import java.io.*;

  public class testa

  public static void mainString[] args throws IOException

  float? x;

  InputStreamReader reader=new InputStreamReaderSystem.in;

  BufferedReader input=new BufferedReaderreader;

  System.out.println"请输入x:";

  String temp=input.readLine;

  x =Float.parseFloattemp;

  ifx@0==0

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

  else

  ifx%4==0

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

  else System.out.println+x+"不是闰年";

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

  import java.io.*;

  public class ka

  public static void mainString[] args throws IOException

  float? x,y;

  InputStreamReader readerx=new InputStreamReaderSystem.in;

  BufferedReader inputx=new BufferedReaderreaderx;

  System.out.println"请输入x:";

  String tempx=inputx.readLine;

  x = Float.parseFloattempx;

  InputStreamReader readery=new InputStreamReaderSystem.in;

  BufferedReader inputy=new BufferedReaderreadery;

  System.out.println"请输入y:";

  String tempy=inputy.readLine;

  y= Float.parseFloattempy;

  ifx

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

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

  else

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

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

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

  import java.io.*;

  public class ka

  public static void mainString[] args throws IOException

  float? x,y,m;

  InputStreamReader readerx=new InputStreamReaderSystem.in;

  BufferedReader inputx=new BufferedReaderreaderx;

  System.out.println"请输入x:";

  String tempx=inputx.readLine;

  x = Float.parseFloattempx;

  InputStreamReader readery=new InputStreamReaderSystem.in;

  BufferedReader inputy=new BufferedReaderreadery;

  System.out.println"请输入y:";

  String tempy=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? x>0

  y=???? 0? x=0

  -x? x<0

  import java.io.*;

  public class testa

  public static void mainString[] args throws IOException

  float? x,y;

  y=0;

  InputStreamReader reader=new InputStreamReaderSystem.in;

  BufferedReader input=new BufferedReaderreader;

  System.out.println"请输入x:";

  String temp=input.readLine;

  x = Float.parseFloattemp;

  ifx>0

  y=x;

  ifx==0

  y=0;

  ifx<0

  y=-x;

  System.out.println"y="+y;

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

  x-1? x>1

  y=???? 0? -1≤x≤1

  x+10? x<-1

  import java.io.*;

  public class testa

  public static void mainString[] args throws IOException

  float? x,y;

  y=0;

  InputStreamReader reader=new InputStreamReaderSystem.in;

  BufferedReader input=new BufferedReaderreader;

  System.out.println"请输入x:";

  String temp=input.readLine;

  x = Float.parseFloattemp;

  ifx>1

  y=x-1;

  if1.0>=x&&x>=-1.0

  y=0;

  ifx<-1

  y=x+10;

  System.out.println"y="+y;

    考试题二:

  1、 编写程序,实现1到100之间整数的累加并输出运算结果。

  public class a

  public static void mainString[] args

  int i,s=0;

  fori=1;i<=100;i++

  s=s+i;

  System.out.println"1到100的累加和是"+s;

  2、编写程序,计算1~100中奇数的累加和并输出。

  public class a

  public static void mainString[] args

  int i,s=0;

  fori=1;i<=100;i++

  ifi%2!=0

  s=s+i;

  System.out.println"1到100的奇数累加和是"+s;

  3、编写程序,计算1~100中偶数的累加和并输出。

  public class a

  public static void mainString[] args

  int i,s=0;

  fori=1;i<=100;i++

  ifi%2==0

  s=s+i;

  System.out.println"1到100的偶数累加和是"+s;

  4、编写程序,计算10的阶乘并输出运算结果。

  public class a

  public static void mainString[] args

  int i,s=1;

  fori=1;i<=10;i++

  s=s*i;

  System.out.println"10的阶乘是"+s;

  5、编写程序,计算1、2、3...的累加和,条件是和小于50。

  public class a

  public static void mainString[] args

  int i=1,s=0;

  label:

  whiletrue

  ? s=s+i;

  i++;

  ifs>50

  s=s+1-i;

  break;

  System.out.println"从1开始的累加和小于50的累加和是"+s;

  6、编写程序,计算偶数2、4、6...的累加和,条件是和小于50。

  public class a

  public static void mainString[] args

  int i=1,s=0;

  label:

  whiletrue

  ? s=s+2*i;

  i++;

  ifs>50

  s=s-2*i+2*1;

  break;

  System.out.println"从2开始的偶数累加和小于50的累加和是"+s;

  7、编写程序,输出下列图案:

  *

  ***

  *****

  *******

  public class a

  ???????? public static void mainString[] args

  int i,k;

  fori=1;i<=4;i++

  fork=1;k<=2*i-1;k++

  System.out.print"*";

  System.out.println;

  8、编写程序,输出下列图案:

  *

  ***

  *****

  *******

  public class a

  ???????? public static void mainString[] args

  int i,j,k;

  fori=1;i<=4;i++

  forj=1;j<=8-2*i;j++

  System.out.print" ";

  fork=1;k<=2*i-1;k++

  System.out.print"*";

  System.out.println;

  9、编写程序,输出下列图案:

  *******

  *****

  ***

  *

  public class a

  ???????? public static void mainString[] args

  int i,j,k;

  fori=1;i<=4;i++

  forj=1;j<=2*i-2;j++

  System.out.print" ";

  fork=1;k<=9-2*i;k++

  System.out.print"*";

  System.out.println;

  10、编写程序在终端打印1~100之间的素数。

  public class a

  ???????? public static void mainString[] args

  int i,j;

  label:

  fori=2;i<=100;i++

  ????? forj=2;jifi%j==0

  continue label;

  System.out.print+i;

  System.out.println;

  11、编写一个java程序,用穷举法找出2~50之间的素数,并打印出来。

  public class s

  public static void mainString args[]

  int i,j,k ;

  boolean flag ;

  for i=2;i<=50 ;i++

  flag =true ;

  k=i/2 ;

  for j=2;j<=k ;j++

  if i%j==0

  flag = false ;

  break ;

  if flag

  System.out.printlni+"" ;

  12、编写一自定义方法,找出两个数中的最大数,并main方法中验证。

  public class a

  static double Maxdouble x,double y

  ?? double t;

  ifx>=y

  t=x;

  else

  t=y;????

  return t;

  public static void mainString[] args

  double x,y,m;

  x=549.265;

  y=56.28;

  m =Ma**,y;

  System.out.println"最大数是"+m;

  System.out.println"x="+x+"y="+y;

  ifm>=x&&y<=m

  System.out.println"ture";

  else

  System.out.println"flase";

  13、编写一自定义方法,找出两个数中的最小数,并main方法中验证。

  public class a

  static double Mindouble x,double y

  ?? double t;

  ifx<=y

  t=x;

  else

  t=y;????

  return t;

  public static void mainString[] args

  double x,y,m;

  x=245.38;

  y=525.63;

  m =Minx,y;

  System.out.println"最小数是"+m;

  System.out.println"x="+x+"y="+y;

  ifm<=x&&y>=m

  System.out.println"ture";

  else

  System.out.println"flase";

  14、编程,找出长度为10的数组中,数组元素的最大值,并输出。

  public class a

  public static void mainString[] args

  double x[]=25.3,56.3,15.3,125.25,465.36,456.32,458.21,456.325,4856.3215,41.6;

  double m= x[0];

  int i;

  fori=0;i<10;i++

  if m<=x[i]

  m=x[i];

  System.out.println"最大数是"+m;

  15、编程,找出长度为10的数组中,数组元素的最小值,并输出。

  public class a

  public static void mainString[] args

  double x[]=25.3,56.3,15.3,125.25,465.36,456.32,458.21,456.325,4856.3215,41.6;

  double m=x[0];

  int i;

  fori=0;i<10;i++

  if m>=x[i]

  m=x[i];

  System.out.println"最小数是"+m;

  16、编程,找出长度为10的数组中,数组元素的最大值和最小值,并输出。

  public class a

  public static void mainString[] args

  double x[]=25.3,56.3,15.3,125.25,465.36,456.32,458.21,456.325,4856.3215,41.6;

推荐访问:

【9月计算机二级考试JAVA考试题及答案(2023年)】相关文章:

1.农村党总支存在的问题举例(2篇)

2.农业技术推广服务项目实施方案(6篇)

3.军训典型事例描述(3篇)

4.内部控制规范与实际工作相结合(7篇)

5.写作能力不足自我批评(7篇)