Which form of loop seems to work best? Why?publicclassDoWhileLoop {publicstaticvoidmain(String[] args) {inttotal = 0;inti = 1;do{total += i;i++;} while(i <=100 );System.out.println(total);}}Lab Manual Chapter 63/27/184
4) You can test to see if an integer, x, is even or odd using the Boolean expression (x / 2) * 2 == x. Integers that are even make this expression true, and odd integers make the expression false. Use a for loop to iterate five times. In each iteration, request an integer from the user. Print each integer the user types, and whether it is even or odd. Keep up with the number of even and odd integers the user types, and print “Done” when finished, so the user won’t try to type another integer. Finally, print out the number of even and odd integers that were entered.importjava.util.Scanner;publicclassForLoops {publicstaticvoidmain(String[] args) {Scanner in = newScanner(System.in);intodd= 0;inteven= 0;for(intcount=1; count<=5; count++) {System.out.print("Enter an integer: ");intx = in.nextInt();if((x / 2) * 2 == x) {System.out.println(x + " is even");} else{System.out.println(x + " is odd");}}in.close();System.out.println("Done");}}COMPUTER SCIENCE MAJORS5*) One of the oldest numerical algorithms was described by the Greek mathematician, Euclid, in 300 B.C. That algorithm is described in Book VII of Euclid’s multi-volume work Elements. It is a simple but very effective algorithm that computes the greatest common divisor of two given integers. For instance, given integers 24 and 18, the greatest common divisor is 6, because 6 is the largestinteger that divides evenly into both 24 and 18. We will denote the greatest common divisor of x and y as gcd(x, y). The algorithm is based on the clever idea that the gcd(x, y) = gcd(x – y, y) if x >= y. The algorithm consists of a series of steps (loop iterations) where the “larger” integer is replaced by the difference of the larger and smaller integer. Lab Manual Chapter 63/27/185
In the example below, we compute gcd(72, 54) and list each loop iteration computation on a separate line. The whole process stops when one of the integers becomes zero. When this happens, the greatest common divisor is the non-zero integer.gcd(72, 54) = gcd(72 – 54, 54) = gcd(18, 54)gcd(18, 54) = gcd(18, 54 – 18) = gcd(18, 36)gcd(18, 36) = gcd(18, 36 – 18) = gcd(18, 18)gcd(18, 18) = gcd(18 – 18, 18) = gcd(0, 18) = 18To summarize: Create a loop, and subtract the smaller integer from the larger one (if the integers are equal you may choose either one as the “larger”) during each iteration. Replace the larger integer with the computed difference. Continue looping until one of the integers becomes zero.Print out the non-zero integer. Use the code below to prompt the user for the two integers.public class GCD{public static void main(String[] args){Scanner in = new Scanner(System.in);System.out.println("Enter the first integer: ");int x = in.nextInt();System.out.println("x = " + x);System.out.println("Enter the second integer: ");int y = in.nextInt();System.out.println("y = " + y);// Your gcd computation code goes here} }Lab Manual Chapter 63/27/186
6.1) Use nested for loops to produce the following output