Console Input
Objective #1: Read program input using the Scanner class.
Objective #2: Read input from an external file or web page.
import java.io.*; import java.net.*; import java.util.*; public class ReadFromWebPage { public static void main(String [] args) { try { Scanner scan = new Scanner((new URL("http://www.minich.com")).openStream()); while (scan.hasNextLine()) { System.out.println(scan.nextLine()); } } catch (IOException ioe) { System.err.println(ioe); } } }
Objective #3: Obtain input from the user with the showInputDialog method.
import javax.swing.JOptionPane;
public class Junk
{
public static void main(String[] args)
{
String name = JOptionPane.showInputDialog("enter your name");
JOptionPane.showMessageDialog(null, "Goodbye " + name);
}
}