Re: How to detect blank input using Scanner?
- From: "Taria" <mchew02@xxxxxxxxxxx>
- Date: 28 Jan 2007 14:00:40 -0800
We can't tell what you are doing without the code. A small, compilabletest program is always helpful especially if it doesn't do what you want.
Remember to compare Strings use .equals() not ==.
--
Knute Johnson
I thought the .equals would have worked! But it still produces the
same result. I have included a small compilable portion of my
program. All I want it to do is assign 'grades.dat' should the user
hit the enter key.
import java.util.Scanner;
public class Test1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the names of your input file:
<grades.dat> ");
// file to be read
String fileNameR = input.nextLine();
// if no input is given, defaults to "grades.dat"
if (fileNameR.equals(null)) {
fileNameR = "grades.dat";
}
System.out.print("\nProcessing " + fileNameR + ". \n");
}
}
// end program
The if statement is never evaluated to be true. Any help is
appreciated.
Puzzled Marion
.
- Follow-Ups:
- Re: How to detect blank input using Scanner?
- From: Knute Johnson
- Re: How to detect blank input using Scanner?
- References:
- 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 do you execute a JAR file?
- Next by Date: Re: How to detect blank input using Scanner?
- Previous by thread: Re: How to detect blank input using Scanner?
- Next by thread: Re: How to detect blank input using Scanner?
- Index(es):