//MoreVariables.java //more demo of basic variables of int, String, and double type. //demo of input and output with JOptionPane windows import javax.swing.*; //for JOptionPane public class MoreVariables { public static void main (String [] args) { String name, input; //String type for string of characters int age; //int for integer value //double for real number value (can have .) double radius, circumference, area; //Use int for counting, double for measuring. name = "joe"; //assign to String object System.out.println( "Welcome: " + name ); name = name + "smith"; //+ is string concatenation System.out.println( "and now it's: " + name ); String firstName, lastName; firstName = "Fred"; lastName = "Smith"; name = firstName + " " + lastName; System.out.println( "Welcome: " + name ); //*********************************************** //JOptionPane input and output dialog windows. //showInputDialog method has prompt string parameter, // returns a String, assign it to a string variable: name = JOptionPane.showInputDialog( "Enter your name please" ); //showMessageDialog displays a string JOptionPane.showMessageDialog( null, "Welcome: " + name ); //null must be the first argument. //2nd argument is string, here concatenation. //*********************************************** input = JOptionPane.showInputDialog( "Enter your age in years" ); //to input an int, need to convert String to int: age = Integer.parseInt( input ); //extremely finicky age = age + 1; JOptionPane.showMessageDialog( null, "Next birthday you will be: " + age ); //*********************************************** input = JOptionPane.showInputDialog( "Enter radius of a circle" ); //to input a double, need to convert String to double: radius = Double.parseDouble( input ); circumference = 2 * Math.PI * radius; area = Math.PI * radius*radius; JOptionPane.showMessageDialog( null, "Circumference=" + circumference + " Area=" + area); } }