My issue
whats my mistake
My code
import java.util.Scanner;
class GCDBruteForce {
// Solution as follows
public static int gcdBruteForce(int a, int b) {
// Find the smaller of the two numbers
int temp =Math.min(a,b);
// Start from the smaller number and work our way down
if(a%temp == 0 || b%temp == 0){
System.out.println(temp);
}
else{
temp=temp-1;
}
// This line should never be reached for positive integers
return 1;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Get test cases 't'
int t = scanner.nextInt();
for (int i = 0; i < t; i++) {
// Get user input
int a = scanner.nextInt();
int b = scanner.nextInt();
// Calculate and print the GCD
int result = gcdBruteForce(a, b);
System.out.println(result);
}
scanner.close();
}
}
Learning course: Design and Analysis of Algorithms
Problem Link: Consecutive Integer Checking to find GCD in Design and Analysis of Algorithms