View Single Post
Old Apr 5th, 2008, 12:20 AM   #4
kewlgeye
Programmer
 
Join Date: Jan 2008
Posts: 54
Rep Power: 1 kewlgeye is on a distinguished road
Question Re: Java Entering a Number or Letter

Quote:
Originally Posted by Jabo View Post
This should be one statement using the AND operator to make sure it's both not below 1 and not above 4
java Syntax (Toggle Plain Text)
  1. 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.


java Syntax (Toggle Plain Text)
  1. import java.util.*;
  2.  
  3. public class Entering_A_Number
  4. {
  5.  
  6. static Scanner console = new Scanner(System.in);
  7.  
  8. public static void main(String[] args)
  9. {
  10.  
  11. String number;
  12.  
  13. System.out.println("Please enter a number or a letter: ");
  14. number = console.nextLine();
  15.  
  16.  
  17.  
  18. if (number = "1")
  19. if (number = "2")
  20. if (number = "3")
  21. if (number = "4")
  22. if (number = "a")
  23. if (number = "b")
  24. System.out.println("Congratulations you entered " + number);
  25. else
  26. System.out.println("You have entered an invalid key " + number);
  27.  
  28.  
  29.  
  30. System.exit(0);
  31. }
  32. }
kewlgeye is offline   Reply With Quote