返回列表 發帖
  1. import java.util.Scanner;


  2. public class OP321 {
  3.            static Scanner input = new Scanner(System.in);
  4.             public static void main(String[] args) {
  5.                 test();
  6.                 test();
  7.                 test();
  8.                 test();
  9.             }
  10.           
  11.             public static void test() {
  12.                     System.out.println("enter an integer:");
  13.                 int a=input.nextInt();
  14.                if(a%2==0&&a%3==0&&a%6==0)
  15.                 {
  16.                         System.out.println(a+"是2、3、6的倍數");
  17.                 }
  18.                  else if(a%2==0&&a%3==0)
  19.                 {
  20.                         System.out.println(a+"是2,3的倍數");      
  21.                         
  22.                 }   
  23.                  else if(a%2==0)
  24.                 {
  25.                          
  26.                        
  27.                                 System.out.println(a+"是2的倍數");
  28.                              
  29.                 }
  30.                  else if(a%3==0)
  31.                         {
  32.                                  
  33.                                
  34.                                         System.out.println(a+"是3的倍數");
  35.                                      
  36.                         }
  37.         
  38.        
  39.        
  40.                 else
  41.                 {
  42.                         System.out.println(a+"不是2、3、6的倍數");       
  43.                 }
  44.             }
  45.         }
複製代碼

TOP

  1. import java.util.Scanner;


  2. public class OP321 {
  3.            static Scanner input = new Scanner(System.in);
  4.             public static void main(String[] args) {
  5.                 test();
  6.                 test();
  7.                 test();
  8.                 test();
  9.             }
  10.           
  11.             public static void test() {
  12.                     System.out.println("enter an integer:");
  13.                 int a=input.nextInt();
  14.                
  15.                   if(a%2==0&&a%3==0)
  16.                 {
  17.                         System.out.println(a+"是2,3、6的倍數");      
  18.                         
  19.                 }   
  20.                  else if(a%2==0)
  21.                 {
  22.                          
  23.                        
  24.                                 System.out.println(a+"是2的倍數");
  25.                              
  26.                 }
  27.                  else if(a%3==0)
  28.                         {
  29.                                  
  30.                                
  31.                                         System.out.println(a+"是3的倍數");
  32.                                      
  33.                         }
  34.         
  35.        
  36.        
  37.                 else
  38.                 {
  39.                         System.out.println(a+"不是2、3、6的倍數");       
  40.                 }
  41.             }
  42.         }
複製代碼

TOP

返回列表