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

作业.

时间:2017-10-15 22:31:31      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:can   mem   test   input   should   java   bsp   lis   inter   

3-1

import java.util.Scanner;
public class Application {
  public static void main(String[] args){
  int number1 =(int)(System.currentTimeMillis() % 10);
  int number2 =(int)(System.currentTimeMillis() /7 % 10);
  Scanner input = new Scanner(System.in);
  System.out.print(
  "What is " + number1 +"+"+number2 +"?");
  int answer= input.nextInt();
  System.out.println(
  number1 +"+"+number2 +"="+answer+"is"+
  (number1 +number2==answer ));

  }

}

技术分享

3-2

import java.util.Scanner;
public class SimpleIfDome {
  public static void main (String[] args) {
  Scanner input = new Scanner(System.in);
  System.out.println("Enter an integer: ");
  int number =input.nextInt();
  if(number % 5 ==0)
    System.out.println("HiFive");
  if(number % 2 ==0)
    System.out.println("HiEven");

}
}

技术分享

3-3

import java.util.Scanner;
public class SubtractionQuiz {
  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.print("What is" + number1 +"-" + number2 + "?");
  Scanner input = new Scanner(System.in);
  int answer = input.nextInt();
  if(number1 - number2 == answer)
    System.out.print("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 ComputeAndInterpretBMI {
  public static void main(String[] args){
  Scanner input = new Scanner(System.in);
  System.out.print("Enter weight in pounds: ");
  double weight = input.nextDouble();
  System.out.print("Enter height in inches:");
  double height = input.nextDouble();
  final double KILOGRAMS_PER_POUND = 0.45359237;
  final double METERS_PER_INCH = 0.0254;
  double weightInKilograms = weight * KILOGRAMS_PER_POUND ;
  double heightInMeters = height * METERS_PER_INCH;
  double bmi = weightInKilograms/(heightInMeters * heightInMeters);
  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");

  }
}

技术分享

3-6

import java.util.Scanner;
public class TestBooleanOperators {
  public static void main(String[] args){
  Scanner input = new Scanner(System.in);
  System.out.print("Enter an integer ");
  int number = input.nextInt();
  if(number % 2 == 0 && number %3 == 0)
    System.out.println(number + "is divisible by 2 and 3.");
  if(number % 2 == 0 || number %3 == 0)
    System.out.println(number + "is divisible by 2 or 3.");
  if(number % 2 == 0 ^ number %3 == 0)
    System.out.println(number + "is divisible by 2 or 3, but not both.");
  }

}

技术分享

3-7

import java.util.Scanner;
public class LeapYear {
  public static void main(String[] args){
    Scanner input = new Scanner(System.in);
    System.out.print("Enter a year ");
    int year = input.nextInt();
    boolean isLeapYear =
   (year % 4 == 0 && year %100 != 0)||(year % 400 == 0);
    System.out.println(year + "is a leap year?" + isLeapYear);
  }

}

技术分享

 

作业.

标签:can   mem   test   input   should   java   bsp   lis   inter   

原文地址:http://www.cnblogs.com/gaojie77/p/7674295.html

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