그래서 나는 자바를 다시 배우고있다. 기본 프로그램 (코드 주석에 설명되어 있음)을 작성하려고하는데 사용자 입력을 받아 배열에 추가하는 방법을 기억하는 데 문제가 있습니다. 나는 사용자 입력을 통해 반복하는 방법을 기억하고 아무거나 입력하면 배열에 입력을 추가 할뿐만 아니라 입력을 테스트하는 것이 더 어려워진다.사용자 입력을 받아서 배열에 추가하기
//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: ");
}
}
}
이것은 내가 지금까지 가지고있는 코드입니다. 누구나 사용자 입력 (입력 테스트)을 반복하고 배열에 입력을 추가하는 방법에 대한 건설적인 비판과 몇 가지 지침을 제공 할 수 있다면 크게 감사하겠습니다.
건배
괜찮 으면이 사용 방법에 대한 예를 들어 주시겠습니까? – hijaked79
편집을 참조하십시오. 그러나 여기에 추가 할 사항이 하나 더 있습니다. 중복 항목 검색. 추가됨. – fge
감사합니다. 코드에 대한 의견을 보내 주셔서 감사 드리며 지금은 더 잘 이해하고 있습니다. – hijaked79