Computer Science Canada Java IO |
Author: | S_Grimm [ Wed Oct 15, 2008 2:39 pm ] | ||
Post subject: | Java IO | ||
Ok, I just finished reading the I\O tutorials in the Tutorial Section in java AND searched the wiki, but they both were about as clear as mud. I understand the import for strings, but i need to get int double, byte, short, or long into a variable that i can manipulate. For example
So I guess what i need is this : How do i read int, double, long, etc... and store it in a variable? Thanks in Advance A\V |
Author: | btiffin [ Wed Oct 15, 2008 2:52 pm ] | ||
Post subject: | Re: Java IO | ||
There are multiple ways; here is one sampler
Hope that helps. Cheers |
Author: | S_Grimm [ Thu Oct 16, 2008 7:42 am ] | ||
Post subject: | Re: Java IO | ||
no, i sort of need a
|
Author: | wtd [ Thu Oct 16, 2008 8:10 am ] |
Post subject: | RE:Java IO |
Let me ask you... can you use System.in to read in a String? |
Author: | [Gandalf] [ Thu Oct 16, 2008 9:04 am ] |
Post subject: | RE:Java IO |
There is a nifty Scanner class in Java 1.5 and up that makes console input much nicer, Google it. It will also save you the String cast. |
Author: | S_Grimm [ Thu Oct 16, 2008 3:02 pm ] | ||||
Post subject: | RE:Java IO | ||||
yes. if you call it through BufferedReader edit. alright. i got it to read an int. now is the time when we say how stupid i am and that biffin was right. i am a complete dumb***. sorry everybody... ![]() now on to my next problem. I was trying to write a method that would allow me to call my own function to read int, but hit a snag. i'll post the code first. then go over my problem.
now, if you take the "num = " out of the in.readInt(); and comment the int num; and System.out.println (num); , the code works fine. what i want to do is be able to have num = in.readInt(); and return a value. can anyone give me a hand with this? edit2: never mind. i had to stick a return and change it from void to int. Ill post the code just incase anyone else whats to look at it and try to suggest something else...
|