Java GDC - Complete Code, Cheat Sheet of Java Programming

Java GDC code start to finish - working.

Typology: Cheat Sheet

2024/2025

Uploaded on 10/19/2025

r4bc9c6w6x
r4bc9c6w6x 🇺🇸

2 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
import java.util.Scanner;
public class GCD {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the first number: ");
int num1 = scanner.nextInt();
System.out.print("Enter the second number: ");
int num2 = scanner.nextInt();
// Calculate GCD using Euclidean algorithm
while (num1 != num2) {
if (num1 > num2) {
num1 -= num2;
} else {
num2 -= num1;
}
}
System.out.println("The GCD of the two numbers is: " + num1);
scanner.close();
}
}

Partial preview of the text

Download Java GDC - Complete Code and more Cheat Sheet Java Programming in PDF only on Docsity!

import java.util.Scanner; public class GCD { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter the first number: "); int num1 = scanner.nextInt(); System.out.print("Enter the second number: "); int num2 = scanner.nextInt(); // Calculate GCD using Euclidean algorithm while (num1 != num2) { if (num1 > num2) { num1 -= num2; } else { num2 -= num1; } } System.out.println("The GCD of the two numbers is: " + num1); scanner.close(); } }