Java Silverに関する問題を出題していきます!
■問題1
次のプログラムをコンパイル、実行した結果として正しいものはどれか。
1 2 3 4 5 6 7 8 | public class Sample { public static void main(String[] args) { int x = 10 ; int y = 20 ; x = x + y; System.out.println(x); } } |
- 10
- 20
- 30
- 5行目でコンパイルエラー
- 実行時エラー
■問題2
次のプログラムをコンパイル、実行した結果として正しいものはどれか。
1 2 3 4 5 6 7 8 9 | public class Sample { public static void main(String[] args) { byte b = 10 ; float f = 5 .6f; char ch = '9' ; boolean b = false ; System.out.println( "実行できました" ); } } |
- 実行できました
- 実行時エラー
- 4行目でコンパイルエラー
- 5行目でコンパイルエラー
- 6行目でコンパイルエラー
■問題3
boolean型の変数に代入できるのは次のうちどれか。
- “true”
- 1 < 5 < 10
- 100 = 100
- 1 == 10
- 0
■問題4
次のプログラムをコンパイル、実行した結果として正しいものはどれか。
1 2 3 4 5 6 7 | public class Sample { public static void main(String[] args) { int x = 3 ; int y = 4 ; System.out.println( "x + y : " + x + y); } } |
- コンパイルエラー
- 実行時エラー
- x + y : 7
- x + y : 34
- x + y : x + y
■問題5
次のプログラムをコンパイル、実行した結果として正しいものはどれか。
1 2 3 4 5 6 7 8 | public class Sample { public static void main(String[] args) { String str1 = "Hello" ; String str2 = " World" ; str1 += str2; System.out.println(str1); } } |
- Hello
- World
- Hello World
- 5行目でコンパイルエラー
- 6行目でコンパイルエラー