
ゆめさくが
Javaの
ログインなしで
この 分野の小分野
- 変数と
スコープと var と文字列(8問) - 配列と
ArrayList(8問)
Javaの 基本 データ型と 文字列の 操作の問題
16 問選ぶと、
変数と
スコープと var と 文字列 問 1次の
宣言の うち、 コンパイルできる ものは どれですか。 問 2次の
コードを 引数なしで 実行した ときの 結果と して 正しい ものは どれですか。 public class Main { static int total; public static void main(String[] args) { int count; if (args.length > 0) { count = args.length; } else { count = -1; } int unused; // (A) System.out.println(total + count); // (B) } }問 3次の
コードを コンパイルして 実行した ときの 結果と して 正しい ものは どれですか。 public class Main { public static void main(String[] args) { int n = 1; { int m = n + 1; System.out.print(m); } int m = 10; // (A) for (int i = 0; i < 2; i++) { int n = i; // (B) System.out.print(n + m); } } }問 4次の
コードを コンパイルして 実行した ときの 結果と して 正しい ものは どれですか。 public class Main { public static void main(String[] args) { var var = 3; // (A) var total = var * 2L; // (B) var a = total, b = 1; // (C) System.out.println(a + b); } }問 5次の
コードを 実行した ときの 出力と して 正しい ものは どれですか。 public class Main { public static void main(String[] args) { String a = " "; String b = ""; System.out.println(a.isEmpty() + " " + a.isBlank() + " " + b.isBlank() + " " + "ab".repeat(2).length()); } }問 6次の
コードを 実行した ときの 結果と して 正しい ものは どれですか。 public class Main { public static void main(String[] args) { String s = "yumesaku"; int i = s.indexOf('u', 2); System.out.print(i + " "); System.out.print(s.charAt(s.length())); } }問 7次の
コードを 実行した ときの 出力と して 正しい ものは どれですか。 public class Main { public static void main(String[] args) { String s = "x"; s += 1 + 2; s = s + 1 + 2; System.out.println(s); } }問 8次の
コードを 実行した ときの 出力と して 正しい ものは どれですか。 public class Main { public static void main(String[] args) { String t = """ ab c\ d """; System.out.print(t.length() + "[" + t.replace(" ", "_").replace("\n", "|") + "]"); } }配列と
ArrayList 問 9次の
コードを コンパイルして 実行した ときの 結果と して 正しい ものは どれですか。 public class Main { public static void main(String[] args) { int[] a, b[]; int c[], d; a = new int[2]; b = new int[2][]; // (A) d = 5; // (B) c = a; System.out.println(a.length + b.length + d + c.length); } }問 10次の
コードを 実行した ときの 結果と して 正しい ものは どれですか。 import java.util.*; public class Main { public static void main(String[] args) { List<String> fixed = List.of("a", "b"); List<String> copy = new ArrayList<>(fixed); copy.add("c"); System.out.print(copy.size()); fixed.add("c"); // (A) } }問 11次の
コードを コンパイルして 実行した ときの 結果と して 正しい ものは どれですか。 public class Main { static int sum(int[] a) { int s = 0; for (int x : a) { s += x; } return s; } public static void main(String[] args) { int[] x = {1, 2, 3,}; // (A) System.out.print(sum(x)); System.out.print(sum(new int[]{4, 5})); // (B) } }問 12次の
コードを 実行した ときの 結果と して 正しい ものは どれですか。 public class Main { public static void main(String[] args) { int[] a = new int[3]; for (int i = 0; i <= a.length; i++) { a[i] = i * 2; System.out.print(a[i]); } } }問 13次の
コードを 実行した ときの 出力と して 正しい ものは どれですか。 public class Main { public static void main(String[] args) { int[][] g = {{1, 2, 3}, {4}, {}}; int total = 0; for (int[] row : g) { total += row.length; } System.out.println(g.length + " " + total + " " + g[1][0]); } }問 14次の
コードを 実行した ときの 出力と して 正しい ものは どれですか。 import java.util.*; public class Main { public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("a"); list.add("c"); list.add(1, "b"); String old = list.set(2, "d"); list.remove("a"); System.out.println(old + list + list.size()); } }問 15java.util.* を
import している とき、 次の 文の うちコンパイルエラーに なる ものは どれですか。 問 16次の
コードを 実行した ときの 結果と して 正しい ものは どれですか。 import java.util.*; public class Main { public static void main(String[] args) { List<Integer> nums = new ArrayList<>(List.of(1, 2, 3, 4)); for (Integer n : nums) { if (n == 2) { nums.remove(n); // (A) } } System.out.println(nums); } }
16 問中 0 問に答えました
解説の一覧
解いた
変数と スコープと var と文字列
問1次の 宣言の うち、 コンパイルできる ものは どれですか。
正解は
問2次の コードを 引数なしで 実行した ときの 結果として 正しい ものは どれですか。
public class Main {
static int total;
public static void main(String[] args) {
int count;
if (args.length > 0) {
count = args.length;
} else {
count = -1;
}
int unused; // (A)
System.out.println(total + count); // (B)
}
}正解は
問3次の コードを コンパイルして 実行した ときの 結果として 正しい ものは どれですか。
public class Main {
public static void main(String[] args) {
int n = 1;
{
int m = n + 1;
System.out.print(m);
}
int m = 10; // (A)
for (int i = 0; i < 2; i++) {
int n = i; // (B)
System.out.print(n + m);
}
}
}正解は
問4次の コードを コンパイルして 実行した ときの 結果として 正しい ものは どれですか。
public class Main {
public static void main(String[] args) {
var var = 3; // (A)
var total = var * 2L; // (B)
var a = total, b = 1; // (C)
System.out.println(a + b);
}
}正解は
問5次の コードを 実行した ときの 出力として 正しい ものは どれですか。
public class Main {
public static void main(String[] args) {
String a = " ";
String b = "";
System.out.println(a.isEmpty() + " " + a.isBlank() + " " + b.isBlank() + " " + "ab".repeat(2).length());
}
}正解は
問6次の コードを 実行した ときの 結果として 正しい ものは どれですか。
public class Main {
public static void main(String[] args) {
String s = "yumesaku";
int i = s.indexOf('u', 2);
System.out.print(i + " ");
System.out.print(s.charAt(s.length()));
}
}正解は
問7次の コードを 実行した ときの 出力として 正しい ものは どれですか。
public class Main {
public static void main(String[] args) {
String s = "x";
s += 1 + 2;
s = s + 1 + 2;
System.out.println(s);
}
}正解は
問8次の コードを 実行した ときの 出力として 正しい ものは どれですか。
public class Main {
public static void main(String[] args) {
String t = """
ab
c\
d
""";
System.out.print(t.length() + "[" + t.replace(" ", "_").replace("\n", "|") + "]");
}
}正解は
配列と ArrayList
問9次の コードを コンパイルして 実行した ときの 結果として 正しい ものは どれですか。
public class Main {
public static void main(String[] args) {
int[] a, b[];
int c[], d;
a = new int[2];
b = new int[2][]; // (A)
d = 5; // (B)
c = a;
System.out.println(a.length + b.length + d + c.length);
}
}正解は
問10次の コードを 実行した ときの 結果として 正しい ものは どれですか。
import java.util.*;
public class Main {
public static void main(String[] args) {
List<String> fixed = List.of("a", "b");
List<String> copy = new ArrayList<>(fixed);
copy.add("c");
System.out.print(copy.size());
fixed.add("c"); // (A)
}
}正解は
問11次の コードを コンパイルして 実行した ときの 結果として 正しい ものは どれですか。
public class Main {
static int sum(int[] a) {
int s = 0;
for (int x : a) {
s += x;
}
return s;
}
public static void main(String[] args) {
int[] x = {1, 2, 3,}; // (A)
System.out.print(sum(x));
System.out.print(sum(new int[]{4, 5})); // (B)
}
}正解は
問12次の コードを 実行した ときの 結果として 正しい ものは どれですか。
public class Main {
public static void main(String[] args) {
int[] a = new int[3];
for (int i = 0; i <= a.length; i++) {
a[i] = i * 2;
System.out.print(a[i]);
}
}
}正解は
問13次の コードを 実行した ときの 出力として 正しい ものは どれですか。
public class Main {
public static void main(String[] args) {
int[][] g = {{1, 2, 3}, {4}, {}};
int total = 0;
for (int[] row : g) {
total += row.length;
}
System.out.println(g.length + " " + total + " " + g[1][0]);
}
}正解は
問14次の コードを 実行した ときの 出力として 正しい ものは どれですか。
import java.util.*;
public class Main {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
list.add("a");
list.add("c");
list.add(1, "b");
String old = list.set(2, "d");
list.remove("a");
System.out.println(old + list + list.size());
}
}正解は
問15java.util.* を import している とき、 次の 文の うちコンパイルエラーに なる ものは どれですか。
正解は
問16次の コードを 実行した ときの 結果として 正しい ものは どれですか。
import java.util.*;
public class Main {
public static void main(String[] args) {
List<Integer> nums = new ArrayList<>(List.of(1, 2, 3, 4));
for (Integer n : nums) {
if (n == 2) {
nums.remove(n); // (A)
}
}
System.out.println(nums);
}
}正解は
ほかの分野
Java の
概要と 簡単な Java プログラムの作成 main メソッド、
コンパイルと 実行、 パッケージ 演算子と
制御構造 演算子と
分岐と switch、 繰り返しと break と continue クラスの
定義と インスタンスの使用 クラス、
メソッド、 コンストラクタ、 オーバーロード、 static、 アクセス修飾子、 パターン・マッチング、レコード 継承と
インタフェースの使用 継承、
抽象クラス、 オーバーライド、 キャスト、 インタフェースと シール・クラス 例外処理
例外の
種類と try-catch、 try-with-resources、 カスタム例外、 multi-catch
Java Silverの頁に、
続きは ゆめさくで
試験の