// (Extra program; we did not do this one in class!) // // A program that prompts the user for numbers and prints // the difference between each pair of numbers. // This might be a useful idea for you to use in HW5. import java.util.*; public class Difference { public static void main(String[] args) { Scanner console = new Scanner(System.in); System.out.println("Type 10 numbers, and I'll tell you their difference."); // read first number separately to solve fencepost problem System.out.print("Type a number: "); int previous = console.nextInt(); for (int i = 1; i <= 10; i++) { System.out.print("Type a number: "); int next = console.nextInt(); int difference = next - previous; System.out.println("Difference = " + difference); // update the previous for the next pass through the loop previous = next; } } }