Re: How to detect blank input using Scanner?
- From: "Marion" <mchew02@xxxxxxxxxxx>
- Date: 28 Jan 2007 14:33:27 -0800
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. :)
.
- Follow-Ups:
- References:
- How to detect blank input using Scanner?
- From: Taria
- Re: How to detect blank input using Scanner?
- From: Knute Johnson
- Re: How to detect blank input using Scanner?
- From: Taria
- Re: How to detect blank input using Scanner?
- From: Knute Johnson
- How to detect blank input using Scanner?
- Prev by Date: Re: How to detect blank input using Scanner?
- Next by Date: Arraylist
- Previous by thread: Re: How to detect blank input using Scanner?
- Next by thread: Re: How to detect blank input using Scanner?
- Index(es):