// Yazzy Latif // 07/13/2020 // CSE142 // TA: Grace Hopper import java.util.*; // Given a number from the user prints out a sum // to max. public class FunWithNumbers { public static void main(String[] args) { Scanner console = new Scanner(System.in); System.out.print("give me an int--> "); int max = console.nextInt(); /* If statement introduction // conditional execution // relational operator: == < > <= >= != if (n % 2 == 0) { System.out.println("even number"); } else { System.out.println("odd number"); } */ // cumulative sum // add up numbers from 1 to 1000 // Gauss int runningTotal = sumToMax(max); System.out.println("runningTotal = " + runningTotal); } // information flow // how do we get a vslue INTO a method: parameters // how do we get a value OUT of a method: returns // Sums up numbers from 1 to provided max // Returns: int sum of the result // int max: the max parameter to sum to public static int sumToMax(int max) { int runningTotal = 0; for (int i = 1; i <= max; i++) { // runningTotal = runningTotal + something runningTotal = runningTotal + i; } // use runningTotal return runningTotal; } }