Java Silverに関する問題を出題していきます!
問題1
次のプログラムを実行して「合格」と表示させるためには、①にどのようなコードを書けば良いか。
public class Sample { public static void main(String[] args) { ① // ・・・①に当てはまるものを選べ } static String disp(int score) { if(score >= 60) { return "合格"; } else { return "不合格"; } } }
- disp(86);
- disp(54);
- System.out.print(disp(86));
- System.out.print(disp(54));
- 当てはまるものはない
問題2
次のプログラムをコンパイル、実行した結果として正しいものはどれか。
public class Sample { public static void main(String[] args) { int sum = num1(10) + num2(20); System.out.println(sum); } static int num1(int num) { return 1; } static int num2(int num) { return 2; } }
- 「3」と表示
- 「30」と表示
- 何も表示されない
- コンパイルエラー
- 実行時エラー
問題3
次のプログラムをコンパイル、実行した結果として正しいものはどれか。
public class Sample { public static void main(String[] args) { int num = 10; inc(num); System.out.println(num); } static void inc(int n) { n++; } }
- 「10」と表示
- 「11」と表示
- 何も表示されない
- コンパイルエラー
- 実行時エラー
問題4
次のプログラムをコンパイル、実行した結果として正しいものはどれか。
public class Sample { public static void main(String[] args) { int[] nums = { 10, 20, 30 }; inc(nums); System.out.println(nums[0]); } static void inc(int[] array) { array[0]++; } }
- 「10」と表示
- 「11」と表示
- 何も表示されない
- コンパイルエラー
- 実行時エラー
問題5
次のプログラムをコンパイル、実行した結果として正しいものはどれか。
public class Sample { public static void main(String[] args) { String str = "Hello"; appendWolrd(str); System.out.println(str); } static void appendWolrd(String str) { str += "World"; } }
- 「Hello」と表示
- 「HelloWorld」と表示
- 何も表示されない
- コンパイルエラー
- 実行時エラー