/* * Intro to Programming CSE 1310 * University of Texas at Arlington */ package code22mar18; import java.util.Scanner; /** * * @author jcmtiernan */ public class Code22Mar18 { /** * @param args the command line arguments */ public static void main(String[] args) { // Quiz 22 Mar 2018 // Write the output that is produced by the code from *** to *** // practicing reading code //*** int value=0; for (int count=0; count <= 100; count++) { value += count; } System.out.println("The value calculated is: "+value+"\n\n"); // the quiz used the original version of the code that // is now in the addOdds method. int lastOdd = 20; System.out.println("\nfor lastOdd of "+lastOdd+" result is "+ addOdds(lastOdd)); //*** int counter = 8; //default Scanner inValue = new Scanner(System.in); System.out.println("\n\nPlease enter the index location of the value you want: "); int check = inValue.nextInt(); if (check > 0) { counter = check; } System.out.println("\nFor index "+counter+" the Fibonacci value is " +fib(counter)); } public static int addOdds(int lastOdd) { int result = 0; for (int n = 1; n < lastOdd; n+=2) { result += n; //System.out.println("n is "+n+" and result is "+result); } return result; } public static int fib(int counter) { int var = 0; int varMinus1 = 0; int varMinus2 = 1; //System.out.println("fib**Before start, varMinus1 is "+varMinus1+ // " \n\t and varMinus2 is "+varMinus2); for (int k=0; k <= counter; k++) { var = varMinus1 + varMinus2; //System.out.println("fib**At index of "+k+" the value is "+var); varMinus2 = varMinus1; varMinus1 = var; } return var; } }