public class P7 {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int range=scanner.nextInt();
for(int i=1;i<=range;i++){
String stringInput =scanner.nextLine();
String[] total =stringInput.split("\\s");
int length=total.length;
System.out.println(length);
}
}
}
If you input range as 3 it will print its length as 1. But first iteration should print the length after getting stringInput. Moreover when you input range as a String, you will get InputMismatchException. Which is correct. So where is the problem? Thanks.