Quote:
Originally Posted by Jabo
This should be one statement using the AND operator to make sure it's both not below 1 and not above 4
if (number<5 && number >0)
Here you've put single quotes around a, but none of the others.
The first error is understandable, the second one you should have seen if you had only looked. Are you using notepad for your editor? I suggest downloading Jedit at least for creating your files, as it will help you find errors like this quicker. It highlights it like PFO did on what I posted here. Also, post code in the Code brackets using the # above the post editor to make it readable.
|
Yeah, I'm sorry the first post was messed up, I didn't want to submit that file, I was careless. I am using the second posting of code which I will post again. This one seems to work well for me, but I keep receiving an error with either a number or letter, its like their is something wrong with my if statements. I don't know, have a look....
And thanks for replying.
import java.util.*;
public class Entering_A_Number
{
static Scanner console = new Scanner(System.in);
public static void main(String[] args)
{
String number;
System.out.println("Please enter a number or a letter: ");
number = console.nextLine();
if (number = "1")
if (number = "2")
if (number = "3")
if (number = "4")
if (number = "a")
if (number = "b")
System.out.println("Congratulations you entered " + number);
else
System.out.println("You have entered an invalid key " + number);
System.exit(0);
}
}