zoukankan      html  css  js  c++  java
  • Java作业五(2017-10-15)

      /*3-2.程序员:龚猛
        第三章全部例题*/
     1 package zhenshu;
     2 import java.util.Scanner;
     3 public class practise {
     4 
     5     public static void main(String[] args) {
     6         int number1 = (int)(Math.random() * 10);
     7         int number2 = (int)(Math.random() * 10);
     8         
     9         if(number1 < number2) {
    10             int temp = number1;
    11             number1 = number2;
    12             number2 = temp;
    13         }
    14         System.out.print
    15         ("what is" + number1 + "-" + number2 +"?");
    16         Scanner input = new Scanner(System.in);
    17         int answer = input.nextInt();
    18         
    19         if (number1 - number2 == answer)
    20             System.out.println("You are correct!");
    21         else{
    22             System.out.println("Your answer is wrong.");
    23             System.out.println(number1 + "-" + number2 + "should be" + (number1 - number2 ));
    24         }
    25     }
    26 
    27 }
     /*3-3.*/ 
     1 package zhenshu;
     2 import java.util.Scanner;
     3 public class Demo {
     4 
     5     public static void main(String[] args) {
     6         Scanner input = new Scanner (System.in);
     7         System.out.println("Enter an integer:");
     8         int number = input.nextInt();
     9         
    10         if (number % 5 ==0)
    11             System.out.println("HiFive");
    12         
    13         if (number % 2 ==0)
    14             System.out.println("HiEven");
    15 
    16     }
    17 
    18 }
      /*3-3*/
    1
    package zhenshu; 2 import java.util.Scanner; 3 public class bmi { 4 5 private static final char[] Obese = null; 6 7 public static void main(String[] args) { 8 Scanner input = new Scanner(System.in); 9 10 System.out.print("Enter height in pounds:"); 11 double weight = input.nextDouble(); 12 13 System.out.print("Enter height in inches:"); 14 double height = input.nextDouble(); 15 16 final double KILOGRAMS_PER_POUND = 0.45359237; 17 final double METERS_PER_INCH = 0.0254; 18 19 double weightInKilograms = weight * KILOGRAMS_PER_POUND; 20 double heightInMeters = height * METERS_PER_INCH; 21 double bmi = weightInKilograms / (heightInMeters * heightInMeters); 22 23 System.out.println("BMI is" + bmi); 24 if (bmi < 18.5) 25 System.out.println("Underweight"); 26 else if (bmi < 25) 27 System.out.println("Normal"); 28 else if (bmi < 30) 29 System.out.println("overweight"); 30 else 31 System.out.println(Obese); 32 33 34 } 35 36 }
     

  • 相关阅读:
    在String中添加移动构造函数和移动赋值运算符
    自定义String类,并且实现在STL容器中添加自定义的类型
    allocator例子
    Messages的例子
    java unicode转中文
    Oracle Unicode转中文(解码)
    dom4j解析XML
    如何下载HLS视频到本地(m3u8)
    background-position
    XMPP协议实现即时通讯底层书写 (二)-- IOS XMPPFramework Demo+分析
  • 原文地址:https://www.cnblogs.com/chengxuyuanGM/p/7672871.html
Copyright © 2011-2022 走看看