I used an if statement to give the user a custom error message when args.length == 0
. However, when no argument is passed, instead of printing my custom message I get an out of bound error.
String w1 = args[0];
int n1 = Integer.parseInt(args[1]);
for(int x = 0; x < n1; x++) {
System.out.println(w1);
}
String w2 = args[2];
int n2 = Integer.parseInt(args[3]);
for(int b = 0; b < n2; b++){
System.out.println(w2);
}
String w3 = args[4];
int n3 = Integer.parseInt(args[5]);
for(int c = 0; c < n3; c++) {
System.out.println(w3);
}
if(args.length == 0){
System.out.println("Error: No user input.");
return;
}
}