返回列表 發帖
package ghh;

import java.util.Scanner;

public class sgg {
         static Scanner k = new Scanner(System.in);
        public static void main(String[] args){
               
                int w=k.nextInt();
                int y=f(w);
       System.out.print(y);
               
        }
        static int f(int w)
        {
                if(w==1)
                                {
                                return 1;       
                                }
                else
                {
                        return w*f(w-1);
                }
        }

}

TOP

package wwe;

import java.util.Scanner;

public class JPA04 {
        static Scanner k = new Scanner(System.in);
        public static void main(String[] args) {
                // TODO 自動產生的方法 Stub
                System.out.println("Input m: ");
            int m=k.nextInt();
               
            System.out.println("Input n: ");
            int n=k.nextInt();

            
            System.out.println("最大公因數為:"+g(m,n));
        }
        public static int g(int m,int n)
        {
                if(m%n==0)
                {
                        return n;
                }
                else
                {
                        return g(n,m%n);
                }
               
        }

       
       
}

TOP

返回列表