import java.util.Scanner; /** A program to demonstrate simple input and output * * @author Duncan Buell * * Program written: 18 October 2007 */ public class Main1 { public static void main (String[] args) { int inputInt; double inputDouble; String inputString; Scanner console = new Scanner(System.in); // // NOTES: // One thing I have done in this is to put an "XX" string before // and after the output of a number of these values. The reason // for this is simply to show you // // // System.out.printf("Input an int%n"); inputInt = console.nextInt(); System.out.println("println prints this as: " + inputInt); System.out.printf("printf prints as d, 4d, 12d: XX%dXX XX%4dXX XX%12dXX%n", inputInt,inputInt,inputInt); System.out.printf("Input a double%n"); inputDouble = console.nextDouble(); System.out.println("println prints this as: " + inputDouble); System.out.printf("printf prints as f, e, 24.20f: %f %e %24.20f %n", inputDouble,inputDouble,inputDouble); System.out.printf("Input a string%n"); inputString = console.next(); System.out.println("println prints this as: XX" + inputString + "XX"); System.out.printf("printf prints as s: %s%n",inputString); System.out.printf("printf prints as 20s: XX%20sXX%n",inputString); System.out.printf("printf prints as -20s: XX%-20sXX%n",inputString); } } // public class Main1