GCD

import java.util.Scanner; public class GCD { public GCD() { Scanner sc = new Scanner(System.in); System.out.print("Please enter a number: "); int x = sc.nextInt(); System.out.println("Please enter another number to calculate GCF: "); int y = sc.nextInt(); int num = 1; for(int i = 1; i< x; i ++){ if(x % i == 0 && y % i == 0){ num = i; } } System.out.println(num); } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.