close
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.util.Scanner;
public class hw5 extends java.applet.Applet {
public void init() {
Scanner scanner=new Scanner(System.in);
String a=JOptionPane.showInputDialog(null,"請輸入一數值:");
int x=Integer.parseInt(a);
String b=JOptionPane.showInputDialog(null,"請輸入一數值:");
int y=Integer.parseInt(b);
JOptionPane.showMessageDialog(null,"最大公因數:"+gcd(x,y));
}
staticint gcd(int a,int b)
{
if(b==0) return a;
else return gcd(b,a%b);
}
}
import javax.swing.*;
import java.awt.*;
import java.util.Scanner;
public class hw5 extends java.applet.Applet {
public void init() {
Scanner scanner=new Scanner(System.in);
String a=JOptionPane.showInputDialog(null,"請輸入一數值:");
int x=Integer.parseInt(a);
String b=JOptionPane.showInputDialog(null,"請輸入一數值:");
int y=Integer.parseInt(b);
JOptionPane.showMessageDialog(null,"最大公因數:"+gcd(x,y));
}
staticint gcd(int a,int b)
{
if(b==0) return a;
else return gcd(b,a%b);
}
}
全站熱搜
留言列表