We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
for (int i=1; sc.hasNext(); i++) {
String line = sc.nextLine();
System.out.println(i + " "+line);;
}
sc.close();
}
}
// sc.hasNext() causes program to wait, as it checks that there is nothing in input buffer
// so it waits that user might enter something, user enters, it check that input is now
// available, so it enters the loop. now sc.nextLine() assigns the input (which is in buffer)
// to 'line'
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java End-of-file
You are viewing a single comment's thread. Return to all comments →
import java.util.*; public class Solution {
}
// sc.hasNext() causes program to wait, as it checks that there is nothing in input buffer // so it waits that user might enter something, user enters, it check that input is now // available, so it enters the loop. now sc.nextLine() assigns the input (which is in buffer) // to 'line'