博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
第五次作业
阅读量:5905 次
发布时间:2019-06-19

本文共 6960 字,大约阅读时间需要 23 分钟。

import java.util.Scanner;public class Add {    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.println("What is" + number1 + "+" + number2 + "?");        int answer=input.nextInt();//得到答案        System.out.println(number1 + "+" + number2 + "=" + answer + "is" + (number1+number2==answer));//用布尔表达式给答案打分        input.close();    }    }

 

import java.util.Scanner;public class Com {    public static void main(String[] args) {        // TODO Auto-generated method stub        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);//计算BMI        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");//肥胖        input.close();        }}

import java.util.Scanner;public class ComputeTax {    public static void main(String[] args) {        // TODO Auto-generated method stub        Scanner input = new Scanner(System.in);        System.out.print("Enter the taxable income: ");//提示用户输入收入        double income = input.nextDouble();        double tax =0;        if (income <= 8350)//用分支语句计算不同收入应征税            tax = income * 0.10;        else if (income <= 33950)            tax = 8350 * 0.10 + (income - 8350) * 0.15;        else if (income <= 82250)            tax = 8350 * 0.10 + (33950 - 8350) * 0.15 + (income - 33950) * 0.25;        else if (income <= 171550)            tax = 8350 * 0.10 + (33950 - 8350) * 0.15 + (82250 - 33950) * 0.25 + (income - 82250) * 0.28;        else if (income <= 372950)            tax = 8350 * 0.10 + (33950 - 8350) * 0.15 + (82250 - 33950) * 0.25 + (171550 - 82250) * 0.28 + (income - 171550) * 0.33;        else            tax = 8350 * 0.10 + (33950 - 8350) * 0.15 + (82250 - 33950) * 0.25 + (171550 - 82250) * 0.28 + (372950 - 171550) * 0.33 + (income - 372950) * 0.35;        System.out.println("Tax is " + (int)(tax * 100)/100.0);        input.close();    }}

import java.util.Scanner;public class Leap {    public static void main(String[] args) {        // TODO Auto-generated method stub        Scanner input = new Scanner(System.in);        System.out.println("Enter a year: ");        int year = input.nextInt();        boolean isLeapYear =(year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);//如果某年可以被4整除而不能被100整除,或者可以被400整除,那么这一年就是闰年200        System.out.println(year + " is a leap year? " + isLeapYear);        input.close();    }}

import java.util.Scanner;public class Zodia {    public static void main(String[] args) {        // TODO Auto-generated method stub        Scanner input = new Scanner(System.in);        System.out.print("Enter a year: ");        int year = input.nextInt();//输入年份        switch (year %12) {        case 0:System.out.println("monkey");break;        case 1:System.out.println("rooster");break;//鸡        case 2:System.out.println("dog");break;        case 3:System.out.println("pig");break;        case 4:System.out.println("rat");break;//鼠        case 5:System.out.println("ox");break;//牛        case 6:System.out.println("tiger");break;        case 7:System.out.println("rabbit");break;//兔        case 8:System.out.println("dragon");break;        case 9:System.out.println("snake");break;        case 10:System.out.println("horse");break;//马        case 11:System.out.println("sheep");//羊        }        input.close();    }}

import java.util.Scanner;public class Test {    public static void main(String[] args) {        // TODO Auto-generated method stub        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.");//检验一个数是否能同时被2和3整除        if (number % 2 == 0 || number % 3 ==0)            System.out.println(number + " is divisible by 2 or 3.");//检验一个数是否能被2或3整除        if (number % 2 == 0 ^ number % 3 == 0)            System.out.println(number + " is divisible by 2 or 3,but not both.");//检验一个数是否能被2或3整除,但不能同时被这两个数整除        input.close();    }}

import java.util.Scanner;public class Sub {    public static void main(String[] args) {        // TODO Auto-generated method stub        int number1 = (int)(Math.random() * 10);        int number2 = (int)(Math.random() * 10);//随机产生两个一位数的整数        if(number1
number2,交换number1和number2 } System.out.println("Whis 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)); } input.close(); }}

import java.util.Scanner;public class Simple {    public static void main(String[] args) {        // TODO Auto-generated method stub        Scanner input =new Scanner(System.in);        System.out.println("Enter an integer: ");//输入一个整数        int number=input.nextInt();        if (number % 5 == 0)            System.out.println("HiFive");//如果能被5整除就显示HiFive        if (number % 2 == 0)            System.out.println("HiEven");//如果能被2整除就显示HiEven        input.close();    }}

import java.util.Scanner;public class Lottery {    public static void main(String[] args) {        // TODO Auto-generated method stub        int lottery =(int)(Math.random() * 100);        Scanner input = new Scanner(System.in);        System.out.print("Enter your lottery pick (two digits): ");        int guess = input.nextInt();//用户输入一个猜测的数值        int lottery1 = lottery / 10;//得到lottery的十位数的数值        int lottery2 = lottery % 10;//得到lottery的个位数的数值        int guess1 = guess / 10;        int guess2 = guess % 10;        System.out.println("The lottery number is " + lottery);        if (guess == lottery)            System.out.println("Exact match: you win $10,000");        else if (guess2 == lottery1 && guess1 == lottery2)            System.out.println("Exact match: you win $3,000");        else if (guess1 == lottery1 || guess1 == lottery2 || guess2 == lottery1 || guess2 == lottery2)            System.out.println("Exact match: you win $1,000");        else            System.out.println("Sorry, no match.");        input.close();    }}

 

转载于:https://www.cnblogs.com/kongtingting/p/7825331.html

你可能感兴趣的文章
CharacterController平滑移动到某点
查看>>
mui 页面跳转
查看>>
sizeof、strlen
查看>>
go语言time包的学习(Time,Location,Duration,Timer,Ticker)
查看>>
拓扑排序((算法竞赛入门经典)刘汝佳)
查看>>
#leetcode#One Edit Distance
查看>>
Deep Learning Toolboxs
查看>>
Java多线程之~~~线程安全容器的非堵塞容器
查看>>
004_on-my-zsh漂亮的shell
查看>>
委托(5)委托和事件
查看>>
《为什么我们的决策总出错》摘录
查看>>
罗辑思维现象透析
查看>>
14、Java并发性和多线程-Java ThreadLocal
查看>>
SharePoint创建Alternate Access Mapping (AAM)备用訪问映射
查看>>
OAthe2 Login use OkHttpClient and OAuth2RestTemplate
查看>>
链接与加载过程中,几个关键的概念
查看>>
clamp 函数
查看>>
Linux下永久改动MAC地址和ifconfig命令总结
查看>>
一点一点学架构(四)—Spring.NET错误Cannot Resolve Type……
查看>>
线段树基础
查看>>