gpt-4o-2024-08-06· OpenAI
WildChat-4.8M (AI2)
Learn to write for loops. Assignment: Assume a Scanner stdin has already been declared…
- User
Learn to write for loops. Assignment: Assume a Scanner stdin has already been declared and instantiated. Write some code that takes two int inputs from the user and then uses a for loop to calculate their Greatest Common Denominator. Print the result. write in java and add no public class with no comments
- Assistantjava
int num1 = stdin.nextInt(); int num2 = stdin.nextInt(); int gcd = 1; for (int i = 1; i <= Math.min(num1, num2); i++) { if (num1 % i == 0 && num2 % i == 0) { gcd = i; } } System.out.println(gcd);