Hands-on Programming Exercises — Ch. 1-5
%).number % 2 == 0. Otherwise it's odd. Use nextInt() to read an integer.for (int i = 1; i <= 10; i++) and print num + " x " + i + " = " + (num * i) inside the loop.sum = 0 and i = 1. While i <= n, add i to sum and increment i.maxOfThree that takes 3 integers as parameters and returns the maximum. Call it from main.main but inside the class. Use if statements or Math.max() to find the largest. Don't forget return!isPrime that takes an integer and returns true if it's prime, false otherwise. Test it by reading a number from the user.n/2 (or Math.sqrt(n)) and check if n % i == 0. If any divides evenly, it's not prime. Return boolean.factorial that takes an integer n and returns n! (n factorial). Print the result from main.for loop from 1 to n, multiplying a running result. Use long as the return type because factorials get large fast! long result = 1; for (int i = 1; i <= n; i++) result *= i;power that takes a base and an exponent (both integers) and returns baseexponent without using Math.pow(). Use a loop.result = 1. Loop exp times, multiplying result *= base each iteration. Don't use Math.pow() — the goal is to practice loops inside methods!***************for (int i = 1; i <= rows; i++). Inner loop: for (int j = 1; j <= i; j++) — print a star with System.out.print("*"). After the inner loop, use System.out.println() for a new line.+, -, *, /). Use a switch statement to compute and display the result. Handle invalid operators and division by zero.char using input.next().charAt(0). Use switch (operator) with cases for each operation. In the '/' case, check if the second number is 0 before dividing.