import java.io.*;
import java.util.Scanner;
public class GetUserInput {
public static void main (String[] args) {
//System.out.print("Enter your name and press Enter: ");
//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// InputStreamReader isr = new InputStreamReader(System.in);
// BufferedReader br = new BufferedReader(isr);
//
// BufferReader br.
// 1. Create a Scanner using the InputStream available.
Scanner scanner = new Scanner( System.in );
// 2. Don't forget to prompt the user
System.out.print( "Type some data for the program: " );
// 3. Use the Scanner to read a line of text from the user.
String input = scanner.nextLine();
// 4. Now, you can do anything with the input string that you need to.
System.out.println( "input = " + input );
//
String name = null;
// try
// {
// name = br.readLine();
// }
// catch (IOException e) {
// System.out.println("Error!");
// System.exit(1);
//
// }
System.out.println("Your name is " + name);
}
}
Tuesday, 23 January 2018
Related Posts:
Do While in java import javax.swing.JOptionPane;public class DoTest // start attr… Read More
Diamond .java public class Diamond{ public static void main(String[] args)&nbs… Read More
Jframe example in java import java.awt.*;import java.awt.event.*;import javax.swing.*;import … Read More
Sentinel in java import javax.swing.JOptionPane;public class Sentinel{ … Read More
0 comments: