【Java SE17 Silver 模擬試験】A-06

Java SE17 Silver 模擬試験
Java SE17 Silver 模擬試験

問題

次の文字列を配列 states に格納するコードとして正しいものはどれですか。(2つ選択)

CO
CA
NY
DC
IL

選択肢

A) String[] states = new String[5];
      states [0] = "CO";
      states [1] = "CA";
      states [2] = "NY";
      states [3] = "DC";
      states [4] = "IL";
B) String[] states = new String[];
      states = "CO";
      states = "CA";
      states = "NY";
      states = "DC";
      states = "IL";
C) String[] states = new String( "CO", "CA", "NY", "DC", "IL" );
D) String[] states = { "CO", "CA", "NY", "DC", "IL" };
E) String[] states = new String[];
     states[] = { "CO", "CA", "NY", "DC", "IL" };
F) String[] states = new String[5];
      states [1] = "CO";
      states [2] = "CA";
      states [3] = "NY";
      states [4] = "DC";
      states [5] = "IL";

解答

A) String[] states = new String[5];
      states [0] = "CO";
      states [1] = "CA";
      states [2] = "NY";
      states [3] = "DC";
      states [4] = "IL";
B) String[] states = new String[];
      states = "CO";
      states = "CA";
      states = "NY";
      states = "DC";
      states = "IL";
C) String[] states = new String( "CO", "CA", "NY", "DC", "IL" );
D) String[] states = { "CO", "CA", "NY", "DC", "IL" };
E) String[] states = new String[];
     states[] = { "CO", "CA", "NY", "DC", "IL" };
F) String[] states = new String[5];
states [1] = "CO";
states [2] = "CA";
states [3] = "NY";
states [4] = "DC";
states [5] = "IL";

解説

(B), (C), (E), (F) の選択肢は正しい記述ではありません。

前の問題へ SE17_A-05

次の問題へ SE17_A-07


対象資格:Java SE17 認定資格