Java Online Compiler
Example: Java Program to Find GCD of Two Numbers using While loop
C
C++
C#
Java
Python
PHP
Main.java
STDIN
Run
// Java Program to Find GCD of Two Numbers using While loop import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int p, q; // p & q - To store the two positive numbers System.out.println ("-----Enter the two positive integer numbers-----"); p = in.nextInt(); q = in.nextInt(); while (p != q) { if (p > q) { p -= q; } else { q -= p; } } System.out.println ("\nThe GCD number is: " + p); } }
180 90
Output
Clear
ADVERTISEMENTS