is this the way that you input information into a program from a keyboard
cause it does not seem to workCode:Temperature = Keyboard.readint();
dooes anyone know another way to input information from a keybord in java
Printable View
is this the way that you input information into a program from a keyboard
cause it does not seem to workCode:Temperature = Keyboard.readint();
dooes anyone know another way to input information from a keybord in java
No
how do you do it then???
Sorry i was just having a little fun. :lol: 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);
}
}
}
yup that is what i need thanks
:thumb:
actually How would i put that lets say number into a variable that i made
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.