0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Java_組み込みクラスを使ってみよう

Posted at

paizaラーニングforTEAM Java入門編
レッスン8の#08

8-#08
// 組み込みクラスを使う
import java.util.*;

public class Main {
    public static void main(String[] args) {
        // 標準入力からデータを読み込んで表示する
        Scanner sc = new Scanner(System.in); // Scanner型の変数sc_コンストラクタの引数はSystem.in
        ArrayList<String> team = new ArrayList<String>(); // 文字列を要素としたArrayListである変数teamを用意してArrayListオブジェクトを作成して代入
        // 標準入力から複数のデータを読み込む
        while (sc.hasNextLine()) {
            String player = sc.next(); // Scannerオブジェクトのnextメソッドを呼び出して変数playerに代入
            System.out.println(player + "は、荒野を歩いていた。");
            team.add(player); // teamオブジェクトのaddメソッドを呼び出す
        }
        
        for (String member : team) {
            System.out.println(member + "は、モンスターと戦った");
        }
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?