Hello!
I new user in Java.
My english not is nice. But I have Question.
How uses input data from keyboard for a simple program?
I know uses System.io.println "bla bla ..." but how work with input datas.
Thank.
:( :( :(
Printable View
Hello!
I new user in Java.
My english not is nice. But I have Question.
How uses input data from keyboard for a simple program?
I know uses System.io.println "bla bla ..." but how work with input datas.
Thank.
:( :( :(
Hi!
Have you checked out JOptionPane and it's input dialog boxes???
http://java.sun.com/products/jdk/1.2...ptionPane.html
they are pretty helpful for collecting user information.
~Jim
Hi, all
To add to the advice that jimmenees gave:
It is possible to input text from the keyboard using another approach. The following code is for an application where the user has to guess a number between 1 and 10. The user has 3 guesses.
The relevant parts are the BufferedReader method and the readLine(). The code is very basic and doesn't have any error-trapping, but it does show how to input from the keyboard.
import java.io.*;
class MyGuess
{
public static void main (String[] args) throws IOException
{
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
int guess, count, num;
boolean correct=false;
System.out.println("Guess the number I am thinking of...(1-10)");
num=(int)(Math.random()*10+1);
for (count=1; count<4; count++)
{
System.out.print("Guess # "+count+" is: ");
System.out.flush();
guess= Integer.parseInt(stdin.readLine());
if (guess==num)
{
correct=true;
break;
}
}
if (correct)
{
System.out.println("Well done ! It was "+num);
}
else
{
System.out.println("You were wrong. It was "+num);
}
}
}
Hope it helps
JoyousMonkey