0

Below is my java code-

public class TestClass {

public static void main(String args[] ) throws Exception {


    Scanner s = new Scanner(System.in);
    int t = s.nextInt();  //number of test cases

    //aA1 b
    for(int i=0;i<t;i++)
    {

    String name = s.nextLine();

   System.out.println(name);

    String[] values = name.split("\\s");
   System.out.println(values.length);



    }


        s.close();
}
}

Below is my input from STDIN

3
aA1 b
a b c d
aa BB cc DD

Expected Output

aA1 b
2
a b c d
4

Original Output

1
aA1 b
2
a b c d
4

Why am I getting extra 1 in output?

I have tested in-https://www.tutorialspoint.com/compile_java_online.php ?

varmashrivastava
  • 392
  • 5
  • 17

0 Answers0