|
-
Nov 11th, 2004, 05:08 PM
#1
Thread Starter
Lively Member
Question
is this the way that you input information into a program from a keyboard
Code:
Temperature = Keyboard.readint();
cause it does not seem to work
dooes anyone know another way to input information from a keybord in java
-
Nov 11th, 2004, 05:25 PM
#2
Dazed Member
-
Nov 11th, 2004, 05:27 PM
#3
Thread Starter
Lively Member
-
Nov 11th, 2004, 05:33 PM
#4
Dazed Member
Sorry i was just having a little fun. Do you want to read input from the console? The following code just reads in what you typed at the command line and spits it back out, then terminates.
Code:
import java.io.*;
public class Q{
public static void main(String[] agrs){
try{
BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
System.out.println(buff.readLine());
}catch(IOException e){
System.out.println(e);
}
}
}
-
Nov 11th, 2004, 05:44 PM
#5
Thread Starter
Lively Member
yup that is what i need thanks
-
Nov 11th, 2004, 05:49 PM
#6
Dazed Member
-
Nov 11th, 2004, 07:00 PM
#7
Thread Starter
Lively Member
actually How would i put that lets say number into a variable that i made
-
Nov 11th, 2004, 08:04 PM
#8
Dazed Member
readLine() returns a String. So the following would store the string returned into the s variable which has a type of String. String s = buff.readLine(); If you want to store the returned String into a integral type you have to use the parseType(String s) methods found in the Wapper classes such as java.lang.Integer. Then you could do somthing like the following. int i = Integer.parseInt(buff.readLine()); but be prepared to catch a NumberFormatException incase what is being passed into the parseType() method is not a integral representation.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|