Can someone help me with this simple java code and clear my concepts

import java.util.Scanner;

class chara {

public static void main(String args[]) {

int T, l, i;

Scanner sc = new Scanner(System.in);

System.out.println("enter test cases");

T = sc.nextInt();

String S = sc.nextLine();

for (i = 0; i < T; ++i) {

System.out.println("enter a string");

S = sc.nextLine();

System.out.println(S);

}

}

}

On the first iteration it does not ask for input in string it executes to the next line, from the second iteration it asks.Can someone please help me with this basic doubt in java and clear my concepts....

Read More »

By: StackOverFlow - 5 days ago

Related Posts