Results 1 to 4 of 4
- 11-07-2009, 09:15 PM #1
How to make a scanner read an int?
Hey,
i can't manage to make my scanner read an int.
Can you plz help me on how to solve this?
Thanks in advance,Java 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("Gelieve een pin in te geven..."); int p = sc.nextInt(); [B][COLOR="Red"]Here is the problem[/COLOR][/B] if(p.equals(waiterz.getPin())){ System.out.println("U heeft een nieuwe tafel geopend!"); System.out.println("Gelieve een keuze te maken uit het volgende menu..."); System.out.println("1" + ". Drank Toevoegen" + "\n" + "2" + ". Eten Toevoegen" + "\n" + "3" + ". Afrekenen" + "\n" + "4" + ". Bestelling corrigeren" + "\n" + "5" + ". Choose your weapon!");
All the best,
DieterLast edited by Dieter; 11-07-2009 at 09:18 PM.
Programming today is a race between software engineers striving to build bigger and better idiot proof programs,and the Universe trying to produce bigger and better idiots...
- 11-07-2009, 09:23 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
How to solve what?
What does your code do vs what it is supposed to do?
- 11-08-2009, 12:41 AM #3
i wanted my input to be compared to the pin(int) i have given in waiterz.
But it gives me an error in my equels.
Error giving me:
Now i was too stupid to forget that it is not an object or an object reference so i cannot use .equal here. So when i realized that, i simple did this...Java Code:Cannot invoke equals(int) on the primitive type int
And it works now.Java Code:int p = sc.nextInt(); if(p == (waiterz.getPin())){
I'm sorry that i posted befor i thought more about it.
All the best,
DieterProgramming today is a race between software engineers striving to build bigger and better idiot proof programs,and the Universe trying to produce bigger and better idiots...
- 11-08-2009, 01:11 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Nice to hear that you've solve the problem yourself. :) Java API really helpful, seems to you refer it to find the solution. Good luck!
If you've solved the problem, please mark the thread solved from the tools menu.
Similar Threads
-
How to make Scanner read the same line
By mcollins in forum New To JavaReplies: 2Last Post: 03-03-2009, 06:41 AM -
Using Scanner class to read int value
By Java Tip in forum Java TipReplies: 1Last Post: 02-07-2009, 02:47 AM -
Use Scanner to read various types of data from a file
By Java Tip in forum java.langReplies: 0Last Post: 04-17-2008, 07:36 PM -
Using Scanner class to read int
By Java Tip in forum Java TipReplies: 0Last Post: 01-18-2008, 11:50 AM -
Read from console (Scanner Class)
By hey in forum New To JavaReplies: 10Last Post: 12-11-2007, 10:11 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks