だから私はJavaを再学習していて、それからしばらく経ちました。基本的なプログラム(コードコメントで説明されています)を作成しようとしていますが、ユーザー入力を取得して配列に追加する方法を思い出せません。ユーザー入力をループする方法を思い出し、ユーザーが何かを入力したかどうかをテストしたり、何かを入力した場合は配列に入力を追加したりするのに苦労しています。
//This program will ask user for for there favorite four games
//If the answer is blank, it will ask again for a game title
//The program will than store there answers into an array
//The program will than display the array in random order
//it will then give the amount of games in the array with an integer
import java.util.*;
public class MultipleClassesMain {
public static void main(String[] args) {
//Array holds 4 string inputs from user
String gameArray[] = new String[4];
//importing scanner element-------
Scanner input = new Scanner(System.in);
//Introduction---------------
System.out.println("Hey there!!!");
System.out.println("Please tell us four game titles you like to play!!!");
//Asks what game user likes and takes user input into a variable
System.out.println("So what a game you like?: ");
String temp = input.nextLine();
//This loop will test against blank user input
while (temp.equals("") || (temp.equals(" ")){
System.out.println("Your game can't be blank. Enter again: ");
}
}
}
これは私がこれまでに持っているコードです。誰かが私に建設的な批判とユーザー入力(入力のテスト)をループして配列に入力を追加する方法についてのいくつかのポインターを与えることができれば、私はそれを大いに感謝します。
乾杯