返回列表 發帖

305--迴圈階乘降計算

import java.util.Scanner;
public class JPD03 {
    static Scanner keyboard = new Scanner(System.in);
    public static void main(String[] args) {
        test();
        test();
        test();
    }
   
    public static void test() {
        ...
    }
}
Stay hungry,
Stay foolish.

package terror;

import java.util.Scanner;

public class rrrrr {
         static Scanner e = new Scanner(System.in);
            
        public static void main(String[] args) {
                // TODO 自動產生的方法 Stub

                test();
                test();
                test();
                test();
        }

        private static void test() {
                // TODO 自動產生的方法 Stub
                int p = 1;
                System.out.println("Please enter one value:");
                int o=e.nextInt();
                if(o>=1 && o<=10)
                {
                 for(int k=1;k<=o;k++)
             {
                  
                                p=p*k;
                          
             }
                          System.out.println(o+"!="+p);
                }
                else
                {
                        System.out.println("Error,the value is out of range.");
                }
        }       

}

TOP

  1. import java.util.Scanner;
  2. public class JPA03 {
  3.     static Scanner keyboard = new Scanner(System.in);
  4.     public static void main(String[] args) {
  5.         test();
  6.         test();
  7.         test();
  8.     }
  9.    
  10.     public static void test() {
  11.             System.out.print("Please enter one value: ");
  12.         int num=keyboard.nextInt();
  13.         int num1,num2=1;
  14.         if(num>=1 && num<=10)
  15.         {
  16.                 for(num1=1;num1<=num;num1++)
  17.                 {
  18.                         num2=num1*num2;
  19.                 }
  20.                 System.out.print(num+"! = "+num2);
  21.         }
  22.         else{
  23.                 System.out.print("Error. the value is out of the range. ");
  24.         }
  25.     }
  26. }
複製代碼

TOP

  1. package hi87;

  2. import java.util.Scanner;

  3. public class hi78 {

  4.           static Scanner keyboard = new Scanner(System.in);

  5.                  public static void main(String[] args) {
  6.                         test();
  7.                         test();
  8.                         test();
  9.                     }
  10.                     
  11.                     public static void test() {
  12.                             int s=1;
  13.                         System.out.print("Please enter one value =");
  14.                         int a=keyboard.nextInt();
  15.                         if(a>0&&a<=10)
  16.                         {
  17.                                 for(int i=a;i>=1;i--)
  18.                                 {
  19.                                         s=s*i;
  20.                                 }
  21.                                 System.out.println(a+"!="+s);
  22.                         }
  23.                         else
  24.                         {
  25.                                 System.out.println("Error,the value is out of range.");
  26.                         }
  27.                     }
  28.                 }
複製代碼

TOP

返回列表