s.o.s. Help me please!!!!


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: s.o.s. Help me please!!!!

  1. #1
    Join Date
    Aug 2002
    Posts
    1

    Unhappy s.o.s. Help me please!!!!

    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.

  2. #2
    Join Date
    Jul 2002
    Posts
    60
    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

  3. #3
    Join Date
    Sep 2002
    Posts
    124
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center