Skip to content

Instantly share code, notes, and snippets.

@takanakahiko
Created January 3, 2015 10:20
Show Gist options
  • Save takanakahiko/5269035de5966def90b5 to your computer and use it in GitHub Desktop.
Save takanakahiko/5269035de5966def90b5 to your computer and use it in GitHub Desktop.
2つの自然数の最小公約数を求めるプログラム(1.3)
public class CommonDivisor{
public static void main(String[] args){
System.out.println("\tx\ty\tr");
int x = Integer.parseInt(args[0]);
int y = Integer.parseInt(args[1]);
int r = x % y;
System.out.println("\t"+x+"\t"+y+"\t"+r);
while(r!=0){
x = y;
y = r;
r = x % y;
System.out.println("\t"+x+"\t"+y+"\t"+r);
}
System.out.println("最大公約数は"+y+"です");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment