package gcd; import java.util.Scanner; public class Gcd { public static void main (String []args) { int Number1; int Number2; Scanner input = new Scanner(System.in); System.out.println("Welcome to the GCD Program!"); System.out.println("Enter two numbers and ill will give you the GCD"); System.out.println("Enter Number1:"); Number1 = input.nextInt(); System.out.println("Enter Number 2"); Number2 = input.nextInt(); int myGCD = gcdFunction(Number1, Number2); System.out.println("Your GCD is: " + myGCD); } // end of main /****Method 1: GCD function*******/ public static int gcdFunction(int a, int b) { if (a == 0) { return b; } while (b != 0) { if (a > b) { a = a - b; } else { b = b - a; } } // end of the while loop return a; } //end of method } // end of Gcd class
I always had a passion for the field of STEM (Science, Technology, Engineering, and Math) and I knew I wanted to do something to make a difference in the world. I just didn’t know where to start. I was an immigrant in a new country, grew up in a tough environment, and wasn’t sure how… Read More