302班

          java突擊隊(duì)
          posts - 151, comments - 74, trackbacks - 0, articles - 14
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          import javax.swing.JOptionPane;
          public class GreatestCommonDivistor

          {
           public static void main(String[] args)
           {

            //輸入第一個(gè)數(shù)
            String strA=JOptionPane.showInputDialog(null,"Enter the first number:","Input First",JOptionPane.QUESTION_MESSAGE);
               int numA=Integer.parseInt(strA);

          //輸入第二個(gè)數(shù)
            String strB=JOptionPane.showInputDialog(null,"Enter the second number:","Input Second",JOptionPane.QUESTION_MESSAGE);
            int numB=Integer.parseInt(strB);
            

          //建立一個(gè)歷時(shí)值存儲(chǔ)公約數(shù)
            int gcd=1;
            for(int k=1;k<=numA&&k<=numB;k++)
            if(numA%k==0&&numB%k==0)
             gcd=k;

          //輸出結(jié)果
            System.out.println("The greatest common of the two numbers is  "+gcd );
           }
          }

          運(yùn)行結(jié)果如圖:


          主站蜘蛛池模板: 定州市| 萝北县| 潞城市| 吴忠市| 石柱| 宜章县| 尖扎县| 远安县| 扶余县| 澄城县| 九江市| 公安县| 福泉市| 宁城县| 沁阳市| 泽普县| 建昌县| 大洼县| 萍乡市| 呼玛县| 临漳县| 吴忠市| 贞丰县| 清流县| 清水河县| 玉门市| 沐川县| 鲁甸县| 分宜县| 咸阳市| 双鸭山市| 格尔木市| 大渡口区| 临沂市| 崇礼县| 江陵县| 万源市| 郎溪县| 昌都县| 济宁市| 龙陵县|