考试吧

计算机等级

考试吧>等级考试>计算机二级考试>JAVA>模拟试题>正文
2018年3月全国计算机二级Java考试练习题及答案(9)
考试吧 2018-02-12 17:09:03 评论(0)条

  点击查看:2018年3月全国计算机二级Java考试练习题及答案汇总

  填空题

  1 java 源程序编译命令是 (javac)

  2 java 应用程序中有一个main()方法,它前面有三个修饰符是 ( public , static , void )

  3 java语言数据类型可分为两大类,一类称为 ( 基本数据类型 ) ,另一类称为 ( 引用数据类型 )

  4 在转向语句中, ( continue ) 语句使得程序结束本次循环,回到循环的条件测试部分继续执行。

  5设x为float型变量, y为 double型变量, a为 int型变量,已知 x=2.5f, a=7 ,y=4.22 则表达式x+a%3*(int)x%(int)y的值为 ( 4.5 )

  6设x为float型变量, y为 double型变量, a为 int型变量,b 为long 型变量,c为char 型,则表达式x+y*a/x+b/y+c 的值为( double ) 类型 7设有数组定义:int MyIntArray[ ] = { 10 , 20 , 30 , 40 , 50 , 60 , 70}; 则执行以下几个语句后的输出结果是 ( 120 )

  for ( int i = 0 i < MyIntArray.length i + + ) if ( i % 2 = = 1 ) s += MyIntArray[i] System.out.println( s )

  for ( int i = 0 i < MyIntArray.length i + + ) if ( i % 2 = = 1 ) s += MyIntArray[i] System.out.println( s )

  程序阅读

  1.写出以下程序的运行结果。

  class First {

  First(  ) {

  System.out.println ("in First"); } }

  public class Second extends First { Second(  ) {

  System.out.println("in Second"); } public static void main(String[] args) { Second mine= new Second(  ); } }

  程序运行的结果:

  in First in Second

  2.解释程序中语句的含义

  纯文本文件f1.txt中的内容是 abcd

  下面的程序将f1.txt文件中的内容写到f2.txt文件中和屏幕上 import java.io.*;

  public class filecopy {

  public static void main(String[] args) { try {

  StringBuffer str=new StringBuffer(  );

  FileInputStream fin=new FileInputStream("f1.txt");

  意义

  FileOutputStream fout=new FileOutputStream("f2.txt");

  意义

  int c;

  while((c=fin.read(  ))!=-1) {

  fout.write(c); 意义

  str.append((char)c); 意义

  }

  fin.close(  ); fout.close(  );

  String str2=str.toString(  );

  System.out.println(str2); 显示的结果是

  }catch(Exception c) {

  System.out.println(c); } } }

  实例化输入流对象,指定输入流来源文件为f1.txt 实例化输出流对象,指定输出流目标文件为f2.txt 将C写入到输出流对象中

  将整数C转化为字符,并添加到字符串str的尾部 abcd

扫描/长按二维码帮助考试通关
2018年等考报考资讯
2018等考各科通关技巧
2018各科最新预测试卷
2018等考各科备考资料

微信搜索"考试吧"了解更多考试资讯、下载备考资料

展开全文
评论(0条) 发表
Copyright © 2004-
考试吧(m.566.com)北京美满明天科技有限公司
社会统一信用代码:91110108MA01WU311X
帮助中心