Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 14-11-2009
Member
 
Join Date: Nov 2009
Posts: 446
Scanner can't read in java

Hi
I am try a program in java where I need to user the scanner class. The problem is that I can't manage my scanner to read an int. I am posting my code below. Can you please help me to solve this.
Code:
System.out.println("Maak een selectie uit de volgende opties..." + "\n" +
			  "1" + ". Nieuwe tafel openen." + "\n" + 
			  "2" + ". Toon open tafels." + "\n" + 
			  "3" + ". Gebruiker opties");
String a = sc.next();
if(a.equals("1")){
   System.out.println("some text here");
   int p = sc.nextInt(); Here is the problem
   if(p.equals(waiterz.getPin())){
	System.out.println("soem more text here");
        System.out.println("example");
        System.out.println("1" + ". Drank Toevoegen" + "\n" + 
				  "2" + ". Eten Toevoegen" + "\n" + 
				  "3" + ". Afrekenen" + "\n" +
				  "4" + ". Bestelling corrigeren" + "\n" + 
				  "5" + ". Choose your weapon!");
Reply With Quote
  #2  
Old 14-11-2009
Member
 
Join Date: May 2008
Posts: 2,293
Re: Scanner can't read in java

Hello,
I sent through the part of code you posted. I can not find any problem in that. Please post the exact problem you have. you are asking to solve it but solve what that is any one would need an exact query. What does you code want to do and what it is supposed to do. Post your query more exactly and I will try to solve it.
Reply With Quote
  #3  
Old 14-11-2009
Member
 
Join Date: Nov 2009
Posts: 446
Re: Scanner can't read in java

I wanted my input to be compared to the pin(int). But this gives me an error in my equals method.
Error was
Code:
Cannot invoke equals(int) on the primitive type int
I forgot that it is not an object or an object reference, so I can not use equals here. So, I simply did this
Code:
int p = sc.nextInt();
if(p == (waiterz.getPin())){
And it works now.
I'm sorry that i posted befor i thought more about it.
Reply With Quote
  #4  
Old 14-11-2009
Member
 
Join Date: May 2008
Posts: 2,293
Re: Scanner can't read in java

Good
I liked it because you solved the problem by yourself. Java API really helpful, seems to you refer it to find the solution. Refer some more books on java, as much as you will read books you can solve the problems more easily. If any queries do post back.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Scanner can't read in java"
Thread Thread Starter Forum Replies Last Post
Java barcode scanner Rily Software Development 6 28-07-2010 10:33 AM
Scanner & PrintStream Issue in Java visioneye Software Development 3 21-07-2010 05:56 AM
How to add parse in scanner in java? MAGAR Software Development 5 02-03-2010 04:30 PM
How to read user input from console using Scanner class in java? Constantinee Software Development 4 06-02-2010 06:47 PM
Scanner problems (java) Zidaan Software Development 2 25-11-2008 05:24 PM


All times are GMT +5.5. The time now is 04:38 PM.