码迷,mamicode.com
首页 > 其他好文 > 详细

邓艳丽 1636050123

时间:2017-10-16 13:53:48      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:程序员   ogr   height   ble   current   print   []   else   rand   

1 //程序员:邓艳丽    题目3.1
 2 import java.util.Scanner;
 3 public class L {
 4 
 5     public static void main(String[] args) {
 6           int number1=(int)(System.currentTimeMillis()%10);
 7             int number2=(int)(System.currentTimeMillis()/7%10);
 8             @SuppressWarnings("resource")
 9             Scanner input=new Scanner(System.in);
10             System.out.println("What is "+number1+"+"+number2+"?");
11             int answer = input.nextInt();
12             System.out.println(number1+"+"+number2+"="+answer+" is "+(number1+number2==answer)); 
13     }
14 }

1 //程序员:邓艳丽    题目3.2
 2 import java.util.Scanner;
 3 public class L {
 4 
 5     @SuppressWarnings("resource")
 6     public static void main(String[] args) {
 7         Scanner input = new Scanner(System.in);
 8         System.out.println("Enter an integer:");
 9         int number = input.nextInt();
10         if (number % 5 == 0)
11             System.out.println("HiFive");
12         if(number % 2 == 0)
13             System.out.println("HiEven");
14     }
15 }

    题目3.3
import java.util.Scanner;
public class L {

    @SuppressWarnings("resource")
    public static void main(String[] args) {
        int number1 = (int)(Math.random() * 10);
        int number2 = (int)(Math.random() * 10);

        if (number1 < number2)
        {
            int temp = number1;
            number1 = number2;
            number2 = temp;
        }
        System.out.println("What is " + number1 + "-" + number2 + "?");
        Scanner input = new Scanner(System.in);
        int answer = input.nextInt();
        if (number1 - number2 == answer)
            System.out.println("You are correct!");
        else{
            System.out.println("Your answer is wrong.");
            System.out.println(number1 + "-" + number2 + "should be " + (number1-number2));
        }
    }
}


题目3.4 import java.util.Scanner; public class L { @SuppressWarnings("resource") public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter weight in kilograms:"); double weight = input.nextDouble(); System.out.print("Enter height in meters:"); double height = input.nextDouble(); double bmi = weight/(height * height); System.out.println("BMI is " + bmi); if (bmi < 18.5) System.out.println("Underweight"); else if (bmi < 25) System.out.println("Normal"); else if (bmi < 30) System.out.println("Overweight"); else System.out.println("Obese"); } }



1 //程序员:邓艳丽 题目3.6 2 import java.util.Scanner; 3 public class L { 4 5 @SuppressWarnings("resource") 6 public static void main(String[] args) { 7 Scanner input = new Scanner(System.in); 8 9 System.out.print("Enter an integer:"); 10 int number = input.nextInt(); 11 if (number % 2 == 0 && number % 3 ==0) 12 System.out.println(number + " is divisible by 2 and 3."); 13 if (number % 2 == 0 || number % 3 ==0) 14 System.out.println(number + " is divisible by 2 or 3."); 15 if (number % 2 == 0 ^ number % 3 ==0) 16 System.out.println(number + " is divisible by 2 or 3, but not both."); 17 } 18 }





1 //程序员: 邓艳丽 题目3.7 2 import java.util.Scanner; 3 public class L { 4 5 @SuppressWarnings("resource") 6 public static void main(String[] args) { 7 Scanner input = new Scanner(System.in); 8 System.out.print("Enter a year:"); 9 int year = input.nextInt(); 10 boolean isLeapYear = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); 11 System.out.println(year + " is a leap year?" +"\n"+ isLeapYear); 12 } 13 }



技术分享

 

 

 

 

 

 

邓艳丽 1636050123

标签:程序员   ogr   height   ble   current   print   []   else   rand   

原文地址:http://www.cnblogs.com/luhan7/p/7676268.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!