Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to do "cin >> num " in java....

Status
Not open for further replies.

qb828

Programmer
Sep 27, 2000
98
US
hello !
in c++, you can do this:
int num;
cin >> num;

or
char name[80];

cin.getline"(name, 80);

how do you do it in java?

without using textbox or jobpane dialog box?
i want to do in dos command line?
no graphic popping up....
i know how to use graphic ones..
just wondering if there is a way to do it in using text
(without popping up boxes)..
thanks millions

QB
 
Sadly, Java has no internal, easy methods for user input at the command line. There are, however, numerous input classes that you can download for free. I started Java 3 years ago with the SavitchIn.java class, which has all the standard input methods. SavitchIn is all over the web, if you want to check it out.
 
Not very difficult here is a sample.
Code:
import java.io.*;

public class TestInput {
  private static BufferedReader stdIn = new BufferedReader new InputStreamReader(System.in));

  public static void main(String[] args) throws IOException {
    String name = null;

    /* Get Input */
    System.out.print("Enter Name: ");
    System.out.flush();
    name = stdIn.readLine();
  
    System.out.println("Name entered is \"" + name + "\"");
  }

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top