public static int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
// Call: System.out.println(gcd(48, 36));What is printed?
- A
24
- B
4
- C
6
- Dcheck_circle
12
Explanation
gcd(48,36)=gcd(36,12)=gcd(12,0)=12.
AP Computer Science A· difficulty 3/5
public static int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
// Call: System.out.println(gcd(48, 36));What is printed?
24
4
6
12
Explanation
gcd(48,36)=gcd(36,12)=gcd(12,0)=12.
Want 10 more like this — adaptive to your weak spots?