/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package functiontest; import java.util.Scanner; import java.util.InputMismatchException; /** * * @author jcmtiernan */ public class FunctionTest { /** * @param args the command line arguments */ public static void main(String[] args) { int intIterate; int currentSum = 0; int sumOfSums = 0; int MAX = 0; Scanner input = new Scanner(System.in); boolean readError = true; //Error checking System.out.println("Please enter a positive integer for the maximum value: "); do { readError = false; try { MAX = input.nextInt(); if (MAX < 0) { System.out.println("You did not enter a valid integer. Please enter a positive integer: "); readError = true; } } catch (InputMismatchException iME) { //System.out.println("You did not enter a valid input. MAX will be set to 5"); //MAX = 5; System.out.println("You did not enter a valid input. Please enter a positive integer: "); readError = true; } input.nextLine(); } while(readError); System.out.printf("%9s %9s %9s \n","intIterate","currentSum","Sums"); for (intIterate = 0; intIterate <= MAX; intIterate++) //while(intIterate <= MAX) { //previousSUm = currentSum; sumOfSums = currentSum; currentSum = currentSum + intIterate; sumOfSums += currentSum; //sumOfSums = currentSum + previousSum; //sumOfSums = currentSum * 2 - intIterate; System.out.printf("%9d %9d %9d\n",intIterate, currentSum, sumOfSums); //intIterate++; } } }