English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

4 answers

use the Bufferedreader class
see the example below:

// HELLO WORLD PROGRAM 2
// Frans Coenen, Monday 15 January 1999
// Department of Computer Science, The University of Liverpool, UK
import java.io.*;

class HelloWorld2 {
// Create BufferedReader class instance
static InputStreamReader input = new InputStreamReader(System.in);
static BufferedReader keyboardInput = new BufferedReader(input);
public static void main(String[] args) throws IOException {
String name;
System.out.print("What is your name? ");
name = keyboardInput.readLine();
System.out.print("\nHello " + name );
}
}

2007-02-18 22:51:44 · answer #1 · answered by abd 5 · 0 0

//Either string or an integer, you have to use BufferedReader
//I gave the entire program (semantic) instead
//Just study how BufferedReader creates a new class giving "var" the power to access all methods a BufferedReader class holds
//"var" becomes an object of BufferedReader
//".readLine()" is method of class BufferedReader

import java.io.*;
public class Sample
{
private static BufferedReader var = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[]args)throws IOException
{
int age;
System.out.print("WHAT IS YOUR NAME? ");
String mystring = var.readLine();

System.out.println("My name is " + mystring);

System.out.println();
System.out.println("HOW OLD ARE YOU? ");
String mynum = var.readLine();
age = Integer.parseInt(mynum); //chars and ints are different so use parse.

System.out.println("I am " + age);
}
}

2007-02-19 07:05:02 · answer #2 · answered by red scar 2 · 0 0

create an object for the DataInput stream and then invoke it works and it also depends on the way you want the data to take..is it on prompt or from the textbox to the variables.

2007-02-19 06:32:20 · answer #3 · answered by Prash.! 2 · 0 0

hai dear,
Refer this
http://java.sun.com/j2se/1.4.2/docs/api/java/io/package-summary.html

2007-02-19 06:30:08 · answer #4 · answered by dewman_byju 4 · 0 0

fedest.com, questions and answers