I am having some trouble with a gcd program that I have created. My problem is that my output is not formatted correctly, and I believe that I need to use arrays to print it out correctly. THe format for the output is:
Num1 Num2 GCD
Num1 Num2 GCD
for how ever many sets the user specifies.
How would I impliment this?
import java.util.Scanner;
public class GCDcalc{
private static int theGCD(int num1, int num2){
while(num2 >0){
int gcd = num1 % num2;
num1 = num2;
num2 = gcd;
}
return num1;
}
public static void main(String args[]){
Scanner input = new Scanner(System.in);
System.out.println("How many sets would you like to compute? ");
int sets = input.nextInt();
for(int i=0; i<sets; i++){
System.out.println("Please enter the first number: ");
int num1 = input.nextInt();
System.out.println("Please enter the second number: ");
int num2 = input.nextInt();
System.out.println("Number 1: " + num1 + " Number 2: " + num2 + " GCD: " + theGCD(num1, num2));
}
}
}