0

Which I run in eclipse. I am getting an unusual output (see below)

import java.util.Scanner;

public class Sample {

    public static void main(String[] args) {
        int testcase ;
        String s1;
        String s2;
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter test cases");
        testcase = sc.nextInt();

for(int i=1 ; i<=testcase; i++)
{
    System.out.println("Enter String 1");
    s1= sc.nextLine();
    System.out.println("Enter String 2");
    s2= sc.nextLine();
    System.out.println(WeightChecker.checkStringWeight(s1, s2));
}


}

the output is

Enter test cases
2
Enter String 1
Enter String 2
timepass
2
Enter String 1
time
Enter String 2
starts
2

I even used debug and here in first iteration s1="" and s2="" my question is why it is happening here?

and what could be the possible solution for same

I saw people is marking this question to another question but that question is completely different

timepass
  • 11
  • 2

0 Answers0