Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 input
Index -> Programming, Java -> Java Help
Goto page Previous  1, 2, 3, 4  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
wtd




PostPosted: Mon May 01, 2006 4:53 pm   Post subject: (No subject)

The question you should be asking is, how can I convert a string into an integer. If you can read in a string, and you can convert a string to an integer, then logic dictates that you can read in an integer, right? Smile
Sponsor
Sponsor
Sponsor
sponsor
cool dude




PostPosted: Mon May 01, 2006 5:53 pm   Post subject: (No subject)

true. i just thought like in turing, Visual basic u can get input which can be both an integer or a string depending on your variable type. so if i declared a variable type as int it should allow me to get input as integer. i guess u can't do that in java, i might be wrong i dunno? if i am wrong which i presume than how do u convert a string to an integer?

p.s. does someone know a good link that gives java syntax because i know how to program (hopefully) i just don't know the syntax
Tony




PostPosted: Mon May 01, 2006 6:00 pm   Post subject: (No subject)

Sun's resourses for Java are pretty [url=http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Integer.html#Integer(java.lang.String)]awesome[/url]
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
[Gandalf]




PostPosted: Mon May 01, 2006 11:24 pm   Post subject: (No subject)

Exactly what you are asking for is perfectly possible using the Scanner class's [url=http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html#nextInt()]nextInt()[/url] method.
cool dude




PostPosted: Tue May 02, 2006 4:37 pm   Post subject: (No subject)

[Gandalf] wrote:
Exactly what you are asking for is perfectly possible using the Scanner class's [url=http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html#nextInt()]nextInt()[/url] method.


it seems easier but i keep getting the error "cannot resolve symbol - class scanner" and the line that is highlighted is

code:

Scanner in = new Scanner(System.in);


can u please tell me wats wrong with that, because thats the code u wrote. also does it matter which one i use i.e. the scanner or the buffered one?
[Gandalf]




PostPosted: Tue May 02, 2006 4:49 pm   Post subject: (No subject)

Are you using Java 5.0? Have you imported java.util.*?

If you are using a previous version of the SDK you will have to use the other mentioned method, yes. Otherwise, I personally recommend you use the Scanner class for both keyboard and file input.
cool dude




PostPosted: Tue May 02, 2006 4:58 pm   Post subject: (No subject)

i just started java so i might be doing something wrong although i pretty much copied your code. i'm using Blue J and yes i imported java.util.* did u test your code yourself? because i think u mentioned that u didn't test it so it might not actually work? i do wanna use your way though because it is easier to remember so can u test it out and tell me if its wrong?
HellblazerX




PostPosted: Tue May 02, 2006 5:01 pm   Post subject: (No subject)

If that's the case, then it probably is because you don't have Java 1.5.0. Otherwise, it wouldn't give an error like the one you got. I suggest you use the other method with BufferedReader.
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Tue May 02, 2006 5:05 pm   Post subject: (No subject)

Indeed, are you sure you have Java 5.0 (1.5.0)? I have tested the code, it works. If you're not sure which version of Java you have (maybe it was installed packaged with BlueJ), check the Java folder (probably) in Program Files/Java.
cool dude




PostPosted: Tue May 02, 2006 6:16 pm   Post subject: (No subject)

[Gandalf] wrote:
Indeed, are you sure you have Java 5.0 (1.5.0)? I have tested the code, it works. If you're not sure which version of Java you have (maybe it was installed packaged with BlueJ), check the Java folder (probably) in Program Files/Java.


k i checked my version and it is 1.5.0 so it should work right? also just to be certain i went to reinstall it here https://sdlc3a.sun.com/ECom/EComActionServlet;jsessionid=9617D14BBA459EED110ED9CE11C0AA6D
cool dude




PostPosted: Tue May 02, 2006 6:24 pm   Post subject: (No subject)

do u have to declare something like in the BufferedReader code?
Krabjuice




PostPosted: Tue May 02, 2006 7:50 pm   Post subject: (No subject)

Scanner in 1.5 only requires that you import the Scanner library: java.util.Scanner

Then, you simply need to create a Scanner object. You already did that, its:
code:
Scanner <name> = new Scanner (System.in);

You can use various methods, ie:
code:
<name>.next() //Get single word, string
<name>.nextLine() //Get a Line of string
<name>.nextInt() //Get a Integer
<name>.Double() //Get a Double
//and so on.
cool dude




PostPosted: Tue May 02, 2006 8:31 pm   Post subject: (No subject)

wow it seems really simple i really wanna be able to use this method. can someone please tell me wat can possibly be wrong when it says "cannot resolve symbol - class scanner". when i click on the question mark it says that "you are using a method here that has not been declared in any visible scope. check the spelling of the name did u mistype it? or did you forget to declare it? or maybe you did declare it but it is not visible from here" it seems like i'm using the correct version of java so wat can i do?
wtd




PostPosted: Tue May 02, 2006 8:40 pm   Post subject: (No subject)

If we could see your code, plain and simple, that would help us diagnose problems.
Tony




PostPosted: Tue May 02, 2006 8:42 pm   Post subject: (No subject)

cool dude wrote:
"cannot resolve symbol - class scanner"

Scanner is capitilized, right?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 4  [ 48 Posts ]
Goto page Previous  1, 2, 3, 4  Next
Jump to:   


Style:  
Search: