// CS7 - Exam 2 practice // conditional statements -------------------------------------- int i=5, j=3; System.out.print(i); if (i%2 == 1) System.out.println(" is cool."); else if (j%2 == 1) System.out.println(" is not cool, but " + j + " is."); else System.out.println(" is not cool, nor is " + j); // nested conditionals ----------------------------------------- final int MAX = 25; final int LIMIT = 100; int num1 = 12; int num2 = 25; int num3 = 87; if (num3 >= MAX) { if (MAX / num2 == 1) System.out.println ("apple"); System.out.println ("orange"); if (LIMIT - num3 > num1 + 2) System.out.println ("pear"); else { System.out.println ("banana"); System.out.println ("kiwi"); } } else if (num2 * 2 == MAX * 2) System.out.println ("grapefruit"); else System.out.println ("lime"); System.out.println ("coconut"); // while loop -------------------------------------------------- final MAX = 20; int num = 13; while (num < MAX) { if (num%2 == 0) System.out.println (num); num++; } // for loop ---------------------------------------------------- for (int count1=1; count1 <= 7; count1++) { for (int count2=1; count2 <= 5; count2++) System.out.print ("#"); System.out.println(); } // method practice (a full program) ---------------------------- class shake { public static void main (String[] args) { for (int i=13, j=9; i+j > 0; i++, j++) { i = shakeItUp(i); j = shakeItUp(j); System.out.println(i + " " + j); } } static int shakeItUp(int a) { if (a % 3 == 0 && a > 10) return a*2; return a - 5; } }