Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Euclid algorithm creates common divisor two positive integers with switch statem

ID: 3527702 • Letter: E

Question

Euclid algorithm creates common divisor two positive integers with switch statement in java im stumped please help import java.util.Scanner; import java.math.RoundingMode /** * * @author */ public class CH04PR43 { /** * @param args the command line arguments */ public static void main(String[] args) { // get input from user System.out.println("Greatest Common Divisor Finder"); //console messages System.out.println(); //print a blank line Scanner sc = new Scanner(System.in); //create a Scanner object //convert letter grades until choice does not equal y or Y String choice = "y"; int a = 0; int b = 0; while (choice.equalsIgnoreCase("y")) //user can enter y or Y { System.out.print("Enter first number: "); //get two numbers from user int a = scanner.nextInt(); System.out.print("Enter second number: "); int b = scanner.nextInt(); while (b != 0) { if (a > b) { a -= b; } else { b -= a; } } gcdResult = a; Scanner scanner = new Scanner(System.in); System.out.println("Please enter first number to find GCD"); int a = scanner.nextInt(); System.out.println("Please enter second number to find GCD"); int b = scanner.nextInt(); System.out.println("GCD of two numbers " + a +" and " + b +" is :" + findGCD( a, b)); } private static int findGCD(int number1, int number2) { //base case if(a == 0){ return number1; } return getGCD(number2, a%b); } } System.out.println("Greatest Common Divisor: " + grade); System.out.println("new line"); System.out.print("Continue y/n: "); choice = sc.next(); System.out.println(); } }

Explanation / Answer

import java.util.Scanner; import java.math.RoundingMode /** * * @author */ public class CH04PR43 { /** * @param args the command line arguments */ public static void main(String[] args) { // get input from user System.out.println("Greatest Common Divisor Finder"); //console messages System.out.println(); //print a blank line Scanner sc = new Scanner(System.in); //create a Scanner object //convert letter grades until choice does not equal y or Y String choice = "y"; int a = 0; int b = 0; while (choice.equalsIgnoreCase("y")) //user can enter y or Y { System.out.print("Enter first number: "); //get two numbers from user int a = scanner.nextInt(); System.out.print("Enter second number: "); int b = scanner.nextInt(); while (b != 0) { if (a > b) { a -= b; } else { b -= a; } } gcdResult = a; Scanner scanner = new Scanner(System.in); System.out.println("Please enter first number to find GCD"); int a = scanner.nextInt(); System.out.println("Please enter second number to find GCD"); int b = scanner.nextInt(); System.out.println("GCD of two numbers " + a +" and " + b +" is :" + findGCD( a, b)); } private static int findGCD(int number1, int number2) { //base case if(a == 0){ return number1; } return getGCD(number2, a%b); } } System.out.println("Greatest Common Divisor: " + grade); System.out.println("new line"); System.out.print("Continue y/n: "); choice = sc.next(); System.out.println(); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote