分析如下Java代码,有标注的四行代码中,有错误的是第( )处?
A: port java.io.FileWriter;
B: port java.io.IOException;
C: blic class Test {
D: blic static void main(String[ ] args) {
E: ring str = "Hello World";
F: leWriter fw = null;
G: y {
H: = new FileWriter("c:\\hello.txt"); // 1
I: .write(str); // 2
J: catch (IOException e) {
K: printStackTrace(); // 3
L: finally {
A: port java.io.FileWriter;
B: port java.io.IOException;
C: blic class Test {
D: blic static void main(String[ ] args) {
E: ring str = "Hello World";
F: leWriter fw = null;
G: y {
H: = new FileWriter("c:\\hello.txt"); // 1
I: .write(str); // 2
J: catch (IOException e) {
K: printStackTrace(); // 3
L: finally {
举一反三
- 下列代码执行结果是?( ) class HelloWorld { public static void modifyString(final String str) { str = "Hello World!"; } public static void main(String[] args) { String a = new String("Hello Java"); modifyString(a); System.out.println(“a = ” + a); } } A: a = Hello Java B: a = Hello World C: 代码编译错误 D: 运行时异常
- 有如下代码:public class Test{ public static void main(String args[]) { String str = new String("World"); char ch[] = {'H','e','l','l','o'}; change(str,ch); System.out.println(str + "and" + ch); } public static void change(String str, char ch[]) { str = "Changed"; ch[0] = ' C'; }}运行后输出的结果是: A: Changed and Cello B: World and Cello C: World and CelloChanged and Hello D: World and Hello
- 给定如下java 代码,在下划线处填入( ),代表HelloWorld 类具有main方法,可以独立运行。public class Helloworld { _______{ System.out.println( “ hello world” ) ; } } A: public static void main( String args ) B: static void main( String args[ ] ) C: public static void main( String[ ] strs ) D: public static main( String args[ ] )
- 有如下代码: public class Test{ public static void main(String args[]) { String str = new String("World"); char ch[] = {'H','e','l','l','o'}; change(str,ch); System.out.println(str + "and" + ch); } public static void change(String str, char ch[]) { str = "Changed"; ch[0] = 'C'; } } 运行后输出的结果是:
- 给定一个java程序的代码片断如下,运行后正确的输出结果是( )。String s=”hello, world”;String str = s.replace(“,” , ” ”);System.out.println(str); A: hello world; B: hello, world C: HELLO WORLD D: HELLO ,WORLD;