10.9
import java.util.Scanner; public class AdditionQuiz { public static void main(String[] args) { // TODO 自动生成的方法存根 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)); } }
package cn.wzx.www; import java.util.Scanner; public class SimpleIfDemo { public static void main(String[] args) { // TODO 自动生成的方法存根 Scanner input=new Scanner(System.in); System.out.println("请输入一个数:\n"); int number=input.nextInt(); if(number%5==0) System.out.println("HiFive"); if(number%2==0) System.out.println("HiEven"); } }
package cn.wzx.www;
import java.util.Scanner;
public class SubtractionQuiz {
public static void main(String[] args) {
// TODO 自动生成的方法存根
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("答案正确");
else
{
System.out.println("答案错误");
System.out.println(number1+"-"+number2+"应该是"+(number1-number2));
}
}
}
package cn.wzx.www; import java.util.Scanner; public class ComputeAndInterpretBMI { public static void main(String[] args) { // TODO 自动生成的方法存根 Scanner input=new Scanner(System.in); System.out.println("输入你的重量:\n"); double weight=input.nextDouble(); System.out.println("输入你的身高:\n"); 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("偏瘦"); else if(bmi<25.0) System.out.println("正常"); else if(bmi<30.0) System.out.println("超重"); else System.out.println("过胖"); } }
package cn.wzx.www; import java.util.Scanner; public class TestBooleanOperators { public static void main(String[] args) { // TODO 自动生成的方法存根 Scanner input=new Scanner(System.in); System.out.println("请输入一个数:\n"); int number=input.nextInt(); if(number%2==0&&number%3==0) System.out.println(number + " 能被2和3整除"); if(number%2==0||number%3==0) System.out.println(number + " 能被2或3整除"); if(number%2==0^number%3==0) System.out.println(number + " 能被2或3整除,但不能同时整除"); } }
package cn.wzx.www; import java.util.Scanner; public class LeapYear { public static void main(String[] args) { // TODO 自动生成的方法存根 Scanner input=new Scanner(System.in); System.out.println("请输入一个年份:\n"); int year=input.nextInt(); boolean isLeapYear=(year%4==0&&year%100!=0)||(year%400==0); System.out.println(year+"是闰年吗? "+isLeapYear); } }
package cn.wzx.www; import java.util.Scanner; public class Lottery { public static void main(String[] args) { // TODO 自动生成的方法存根 int lottery=(int)(Math.random()*100); Scanner input=new Scanner(System.in); System.out.println("输入一个两位数:\n"); int guess=input.nextInt(); int lotteryDigit1=lottery/10; int lotteryDigit2=lottery%10; int guessDigit1=guess/10; int guessDigit2=guess%10; System.out.println("这个数字是"+lottery); if(guess==lottery) System.out.println("匹配到彩票的实际顺序,获奖金:10000元"); else if(lotteryDigit2==guessDigit1&&lotteryDigit1==guessDigit2) System.out.println("匹配到彩票的所有数字,获奖金:3000元"); else if(lotteryDigit1==guessDigit1||lotteryDigit2==guessDigit1||lotteryDigit2==guessDigit1||lotteryDigit2==guessDigit2) System.out.println("匹配到彩票的一个数字,获奖金:1000元"); else System.out.println("抱歉,没中奖"); } }
package cn.wzx.www; import java.util.Scanner; public class ChineseZodiac { public static void main(String[] args) { // TODO 自动生成的方法存根 Scanner input=new Scanner(System.in); System.out.println("输入年份:\n"); 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"); break; } } }