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.
According to the question you need to first accept the input but in your loop you are giving output after each line the user enters. How does this make your code crct?
This is my version of code!
int i=0;
Scanner scanner = new Scanner(System.in);
while (scanner.hasNextLine()) {
List<String> tokens = new ArrayList<>();
Scanner lineScanner = new Scanner(scanner.nextLine());
while (lineScanner.hasNext()) {
tokens.add(lineScanner.nextLine());
}
lineScanner.close();
Iterator<String> itr = tokens.iterator();
while(itr.hasNext()){
i++;
System.out.println(i + " " + itr.next());
}
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 →
According to the question you need to first accept the input but in your loop you are giving output after each line the user enters. How does this make your code crct?
This is my version of code!
int i=0; Scanner scanner = new Scanner(System.in);