Re: How to detect blank input using Scanner?



import java.io.*;

public class test6 {
public static void main(String[] args) throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);

String str = br.readLine();
if (str.equals(""))
System.out.println("default");
else
System.out.println(str);
}

}--

Knute Johnson
email s/nospam/knute/- Hide quoted text -- Show quoted text -

Whee! I looked at your code, tried not to flinch at the
BufferedReader code :p (Well, that stuff is totally alien to me.)
But from your code, it sparked a great idea of a solution, I
substituted "null" to "" and voila...it works with the Scanner
class.

Yihaa!

Y'know, I mulled over this small portion of the program longer than
the whole program itself. lol.

Thank you very much Knute, without your advice, I would have never
found this solution.

The elated newbie programmer. :)

.