You are viewing a single comment's thread. Return to all comments →
Look at my code below, I have checked if nextLine() return an empty string or not and if it returns an empty string, i will break the loop
Scanner stdin = new Scanner(System.in); int i = 1; while (stdin.hasNextLine()) { String str = stdin.nextLine(); if(str.isEmpty()) break; System.out.println(i + " " + str); i++; } stdin.close();
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 →
Look at my code below, I have checked if nextLine() return an empty string or not and if it returns an empty string, i will break the loop