本文目录一览:
给定一个java程序的main方法的代码片段如下:假如d 目录下不存在abc.txt文件,下面运行结果是什么呢
a。不存在就会抛出异常。运行catch中的语句。输出‘文件没有发现!’
给定一个java程序的代码片断,如下
选a和c。
public String substring(int beginIndex, int endIndex)
返回一个新字符串,它是此字符串的一个子字符串。该子字符串从指定的 beginIndex
处开始,一直到索引 endIndex - 1
处的字符。因此,该子字符串的长度为 endIndex-beginIndex
。
public int indexOf(String str)
返回第一次出现的指定子字符串在此字符串中的索引。
public char charAt(int index)
返回指定索引处的 char
值。索引范围为从 0 到 length() - 1
。序列的第一个 char
值在索引 0 处,第二个在索引 1 处,依此类推,这类似于数组索引。
JAVA IO小问题
PrintWriter
有自动 flush
的功能,但是必须在构造函数中传入 PrintWriter log = new PrintWriter(fw, true);
,true
才会自动刷。
上面那段代码没有 true
,所以程序结束了也不会将缓存区的东西刷进文件中。
求java习题?
- 给定一个 Java 程序代码,如下:运行编译后,输出结果是()。 (选择一项)
pubilc class Test {
int count = 9;
pubilc void count1() {
int count = 10;
SYstem.out.println("count1" + count);
}
pubilc void count2() {
SYstem.out.println("count2" + count);
}
pubilc static void main(String args[]) {
Test t = new Twst();
t.count1();
t.count2();
}
}
A. count1=9 count2=9
B. count1=10 count2=9
C. count1=10 count2=10
D. count1=9 count2=10
2. 给定 Java 代码,如下:运行时,会产生()类型的异常。(选择一项)
String s = null;
s.concat("abc");
A. AritthmeticException
B. NullpointerException
C. IOException
D. EOFException
3. 给定 Java 代码片段,如下:
Integer a = new Integer(3);
Integer b = new Integer(3);
System.out.println(a == b);
运行后,这段代码将输出()。(选择一项)
A. true
B. false //对象比较用EQUALS
C. 0
D. 1
4. 在 Java 中的布局管理器,以下说法中错误的是(). (选择一项)
A. FlowLayout 以由上到下的方式从左到右排列组件
B. BorderLayout 使用 "东"."西"."南"."北"."居中" 来指定组件的位置
C. GridLayout 可以创建网格布局,网格布局中各组的大小可以任意调整
D. 可以通过容器的 setLayout 方法为容器指定布局管理
5. 在 J2EE 中,下列元素经过排序的集合类是()。(选择一项)
A. LinkedList
B. Stack
C. Hashtable
D. TreeSet
6. 在 Java 中,要想使定义该类所在的包外的类不能访问这个类应用的关键字是()。(选择一项)
A. 不需要任何关键字
B. private
C. final
D. protected
7. 某一 Java 程序中有如下代码:
Datalnputstream din = new DataInputstream(new BufferedInputstream(new FileInputstream("employee.dat")));
假设在 employee.dat
文件中只有如下一段字符:abcdefg
。则:System.out.println(din)
在屏幕上打印()。(选择一项)
A. A
B. B
C. 97
D. 98
8. () 位于集合框架的体系结构的顶层。(选择一项)
A. ArrayList 类
B. Collection 接口
C. Set 接口
D. List 接口
9. Java 程序中读入用户输入的一个值,要求创建一个自定义的异常,如果输入值大于 10,使用 throw 语句显式地引发异常,异常输出信息为“something's wrong!”,语句为()。(选择一项)
A. if (I10) throw Exception("something's wrong!");
B. if (I10) throw Exception e ("something's wrong!");
C. if (I10) throw new Exception("something's wrong!");
D. if (I10) throw new Exception e ("something's wrong!");
11. 下面是 Java 程序中的一些声明,选项中能够通过编译的一项是()。(选择一项)
String s1 = new String("Hello");
String s2 = new String("there");
String s3 = new String();
A. s3 = s1 + s2
B. s3 = s1s2
C. s3 = s1 || s2
D. s3 = s1s2