am new to Java programming.and I just want to print the n strings entered by the user where "n" is the number of test cases entered by the user aswell. so here is my code below ...but nextLine() method is not taking input from the user at the base case(i.e at int i=0
).
the code is
import java.util.Scanner;
import java.io.InputStreamReader;
public class Stringprint{
public static void main(String[] args){
String str;
int testcase;
Scanner scanIn = new Scanner(System.in);
System.out.println("Enter the number of testcases :");
testcase = scanIn.nextInt();
for(int i = 0; i < testcase ; i ++){
System.out.println("Enter the String" + i + ":");
str = scanIn.nextLine();
System.out.println(string);
}
}
}
out put of above code is getting like :
Enter the number of testcases :
4
Enter the String0:
Enter the String1:
hello
hello
Enter the String2:
hai
hai
Enter the String3:
bye
bye
so where am I getting wrong..why it isn't asking input string at i=0
? did i do anything wrong here ?