8

  1 //程序员:马相露
  2    题目3.7
  3   import java.util.Scanner;
  4   public class L {
  5   
  6       @SuppressWarnings("resource")
  7       public static void main(String[] args) {
  8                Scanner input = new Scanner(System.in);
  9               System.out.print("Enter a year:");
 10               int year = input.nextInt();
 11              boolean isLeapYear = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
 12              System.out.println(year + " is a leap year?" +"\n"+ isLeapYear);
 13      }
 14  }
 15 
 16  
 17 
 18  //程序员:马相露  题目3.6
 19   import java.util.Scanner;
 20   public class L {
 21   
 22       @SuppressWarnings("resource")
 23       public static void main(String[] args) {
 24            Scanner input = new Scanner(System.in);
 25   
 26               System.out.print("Enter an integer:");
 27              int number = input.nextInt();
 28              if (number % 2 == 0 && number % 3 ==0)
 29                  System.out.println(number + " is divisible by 2 and 3.");
 30              if (number % 2 == 0 || number % 3 ==0)
 31                  System.out.println(number + " is divisible by 2 or 3.");
 32              if (number % 2 == 0 ^ number % 3 ==0)
 33                  System.out.println(number + " is divisible by 2 or 3, but not both.");
 34      }
 35  }
 36 
 37  
 38 
 39 //程序员:马相露
 40    题目3.4
 41 import java.util.Scanner;
 42 public class L {
 43 
 44     @SuppressWarnings("resource")
 45     public static void main(String[] args) {
 46         Scanner input = new Scanner(System.in);
 47 
 48         System.out.print("Enter weight in kilograms:");
 49         double weight = input.nextDouble();
 50 
 51         System.out.print("Enter height in meters:");
 52         double height = input.nextDouble();
 53 
 54         double bmi = weight/(height * height);
 55 
 56         System.out.println("BMI is " + bmi);
 57         if (bmi < 18.5)
 58             System.out.println("Underweight");
 59         else if (bmi < 25)
 60             System.out.println("Normal");
 61         else if (bmi < 30)
 62             System.out.println("Overweight");
 63         else
 64             System.out.println("Obese");
 65     }
 66 }
 67 
 68  
 69 
 70 //程序员:马相露    题目3.3
 71 import java.util.Scanner;
 72 public class L {
 73 
 74     @SuppressWarnings("resource")
 75     public static void main(String[] args) {
 76         int number1 = (int)(Math.random() * 10);
 77         int number2 = (int)(Math.random() * 10);
 78 
 79         if (number1 < number2)
 80         {
 81             int temp = number1;
 82             number1 = number2;
 83             number2 = temp;
 84         }
 85         System.out.println("What is " + number1 + "-" + number2 + "?");
 86         Scanner input = new Scanner(System.in);
 87         int answer = input.nextInt();
 88         if (number1 - number2 == answer)
 89             System.out.println("You are correct!");
 90         else{
 91             System.out.println("Your answer is wrong.");
 92             System.out.println(number1 + "-" + number2 + "should be " + (number1-number2));
 93         }
 94     }
 95 }
 96 
 97  
 98 
 99 
100   //程序员:马相露
101     题目3.2
102   import java.util.Scanner;
103   public class L {
104   
105       @SuppressWarnings("resource")
106       public static void main(String[] args) {
107           Scanner input = new Scanner(System.in);
108           System.out.println("Enter an integer:");
109           int number = input.nextInt();
110          if (number % 5 == 0)
111              System.out.println("HiFive");
112          if(number % 2 == 0)
113              System.out.println("HiEven");
114      }
115  }
116 
117 
118   //程序员:马相露
119    题目3.1
120   import java.util.Scanner;
121   public class L {
122   
123      public static void main(String[] args) {
124             int number1=(int)(System.currentTimeMillis()%10);
125               int number2=(int)(System.currentTimeMillis()/7%10);
126             @SuppressWarnings("resource")
127               Scanner input=new Scanner(System.in);
128              System.out.println("What is "+number1+"+"+number2+"?");
129              int answer = input.nextInt();
130              System.out.println(number1+"+"+number2+"="+answer+" is "+(number1+number2==answer)); 
131      }
132  }

 

posted @ 2017-12-18 14:21  mxl-1  阅读(140)  评论(0编辑  收藏  举报