/* T01n09.java -- This is T01n08.java with some modifications. * * OK, first off: This is a demonstration program only! I * certainly DO NOT recommend this level of cryptic coding in your programs. * You *want* others to be able to see your intentions easily. Doing * things like initializing variables in print statements will only * serve to confuse people. The point is that Java will let you get away * with stuff like this; it's part of your job as a programmer not to be * tempted by the potential for abuse. */ public class T01n09 { public static void main (String [] args) { final int NUM_SQUARES = 9; // squares on a tic-tac-toe board float currentSum, // total of the values of the squares currentValue; // the cost of the currently considered square int square = 1; // identifier of the current square (1 - 9) System.out.println("Square\t Cost\t Total"); System.out.printf("%6d\t%6.1f\t%6.1f\n",1,currentValue=1,currentSum=1); // System.out.println("1\t" + (currentValue=1) + "\t" + (currentSum=1)); while (++square <= NUM_SQUARES) { currentSum += currentValue *= 2; System.out.printf("%6d\t%6.1f\t%6.1f\n",square,currentValue, currentSum); } System.out.println("The sum to be paid for " + --square + " squares" + " is $" + currentSum/100 + "."); } }