Problem 29

Using Swing for Input

Type in the following code, and get it to compile. Run it, and see what it does.

import javax.swing.*;
public class Prog611 {
  public static void main(String[] args) {
    String name = JOptionPane.showInputDialog("What is your name?");
    
    int age = Integer.parseInt(JOptionPane.showInputDialog("How old are you?"));
    System.out.print("Hello, " + name + ".");
    System.out.println("Next year, you'll be " + (age + 1));
    
    System.exit(0);
  }
}

◄ 28: Modulus Animation 30: A Boring Window ►



Adapted from ProgrammingByDoing.com
©2013 Graham Mitchell

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License.