Results 1 to 4 of 4

Thread: Scanner can't read in java

  1. #1
    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!");

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    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.

  3. #3
    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.

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    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.

Similar Threads

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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,134,575.04929 seconds with 16 queries