Click to See Complete Forum and Search --> : Input help


Darrel104
11-02-2005, 09:22 PM
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)

mr1yh1
11-03-2005, 10:01 AM
scanner or Scanner ?
java is case sensetive, scanner and Scanner are different names.

Darrel104
11-03-2005, 03:03 PM
oh yea i did mess that up but it isnt it just a careless mistake... i edited that out.

mr1yh1
11-03-2005, 04:46 PM
http://java.sun.com/j2se/1.5.0/docs/api/java/util/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);

Darrel104
11-03-2005, 06:42 PM
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?

code here (http://www.skylit.com/javamethods/studentdisk/EasyReader/EasyReader.java)

mr1yh1
11-04-2005, 03:30 AM
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 .

Darrel104
11-04-2005, 06:45 PM
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.

aniseed
11-06-2005, 11:28 PM
Are you using the correct JDK? Scanner would require JDK 1.5

Darrel104
11-07-2005, 04:01 PM
j2sdk1.4.2_10

aniseed
11-08-2005, 12:30 PM
Start by downloading and installing the correct version of SDK.
http://java.sun.com/j2se/1.5.0/download.jsp

tjwit
11-12-2005, 12:55 AM
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 );