Pages

Wednesday, June 6, 2012

Java - read from console, dos prompt

The JAVA file is the following, for an example of reading input values from console:

package javaapplication1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class JavaApplication1 {

    public static void main(String[] args) throws IOException {
       
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
       
        String prompt = "";       
        System.out.println("Enter your name: ");
        prompt = reader.readLine();
        if (prompt.equals("\t"))
            System.out.println("You entered a TAB from your keyboard.");
        else
            System.out.println("Your name is: "+prompt);
       
    }
}

No comments:

Post a Comment