Input help


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 11 of 11

Thread: Input help

  1. #1
    Join Date
    Nov 2005
    Posts
    16

    Input help

    I have been following a book but i can not get the user input thing to work could someone tell me what i am doing wrong? BTW i am using eclipse.

    This is the code i am trying to use:

    public class name {

    public static void main(String[] args) {


    System.out.println("enter your name");
    Scanner console = new Scanner(); // error on this line
    int name = console.readInt();

    System.out.println("The name you entered is: " + name);
    }
    }


    This is the error it is giving me:


    Exception in thread "main" java.lang.Error: Unresolved compilation problems:
    scanner cannot be resolved to a type
    scanner cannot be resolved to a type

    at name.main(name.java:7)
    Last edited by Darrel104; 11-03-2005 at 03:04 PM.

  2. #2
    Join Date
    Sep 2005
    Location
    istanbul / Turkey
    Posts
    133
    scanner or Scanner ?
    java is case sensetive, scanner and Scanner are different names.

  3. #3
    Join Date
    Nov 2005
    Posts
    16
    oh yea i did mess that up but it isnt it just a careless mistake... i edited that out.

  4. #4
    Join Date
    Sep 2005
    Location
    istanbul / Turkey
    Posts
    133
    http://java.sun.com/j2se/1.5.0/docs/...l/Scanner.html
    i looked up Scanner class, but i couldnt see a constructor without arguments . i guess problem was that.

    Scanner console = new Scanner(System.in);

  5. #5
    Join Date
    Nov 2005
    Posts
    16
    I Tried it but it still doesnt work.

    I have found a wedsite with some code on it or something if i create it as anther package would anyone see it working?


  6. #6
    Join Date
    Sep 2005
    Location
    istanbul / Turkey
    Posts
    133
    Code:
    import java.util.Scanner;
    public class name {
    
    public static void main(String[] args) {
    
    System.out.println("enter your name");
    Scanner console = new Scanner(System.in);
    int name = console.nextInt();// readInt() ?
    
    System.out.println("The name you entered is: " + name);
    }
    }
    i suggest you to use an IDE similar JBuilder, netbeans etc..
    they give helpfull warnings or code complete help,
    it will save your time .

  7. #7
    Join Date
    Nov 2005
    Posts
    16
    I downloaded Jcreater but i still can not get it to work so i think i might just do something else because i have spent about 12 hours of my free time trying to fix it but i am not even close.

  8. #8
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    255
    Are you using the correct JDK? Scanner would require JDK 1.5
    Happiness is good health and a bad memory.

  9. #9
    Join Date
    Nov 2005
    Posts
    16
    j2sdk1.4.2_10

  10. #10
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    255
    Start by downloading and installing the correct version of SDK.
    http://java.sun.com/j2se/1.5.0/download.jsp
    Happiness is good health and a bad memory.

  11. #11
    Join Date
    Nov 2005
    Location
    ohio
    Posts
    5
    I don't know if you resolved this, but when I need user input this is what I use


    Scanner scan = new Scanner( System.in );

    System.out.print("Enter your name > ");
    String name = scan.next();
    System.out.println( "The name you entered is " + name );

Similar Threads

  1. Understanding Open xxx For Input As #6
    By AM003295 in forum VB Classic
    Replies: 4
    Last Post: 06-16-2005, 12:47 AM
  2. cursor positioning within input boxes?
    By charlie in forum Web
    Replies: 5
    Last Post: 06-04-2004, 01:08 PM
  3. Replies: 1
    Last Post: 01-09-2002, 07:23 PM
  4. Replies: 0
    Last Post: 12-26-2001, 11:32 AM
  5. Discord in Program
    By N. Richards in forum VB Classic
    Replies: 1
    Last Post: 09-09-2000, 05:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center