I have written this piece of code below and I was wondering if it is possible to validate the code entry for "playername". I need to be able to check to see if anything has been entered into this string by the user and I was wondering if it is possible to do this in any way apart from using a break, as it is not in a loop I cannot use a break. Also when I am getting input from the user I am using a colon as my field delimiter to split the user input up into separate elements of an array. I was wondering if there is any way in checking to see if the correct field delimiter is being used by the user.
import java.util.Scanner;
public class REQ2 {
public static void main (String[] args) {
String playername;
String line;
String[] list = new String[100];
int count = 0;
int score;
int time;
int totalScore =0;
Scanner sc = new Scanner(System.in);
System.out.println("Please enter your name");
playername = sc.nextLine();
System.out.println("Please enter your game achievements (Game name:score:time played) E.g. Minecraft:14:2332");
while (count < 100) {
line = sc.nextLine();
if(line.equals("quit")) {
break;
}
list[count]=line;
System.out.println("list[count]" + list[count]);
count++;
for (int i = 0; i < count; i++) {
line = list[i];
String[] elements = line.split(":");
if (line.length() != 3) {
System.out.println("Error please try again, Please enter in the following format: game name:score:timeplayed");
break;
}
score = Integer.parseInt(elements[1].trim());
time=Integer.parseInt(elements[2].trim());
}
}
}
}