布尔值:
示例:
import java.util.Scanner;
public class Test09 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("请输入折扣:");
double zhekou = input.nextDouble();
int ts = 245;
int wqx = 570;
int wqp = 320;
double tsc = ts * zhekou;
double wqxc = wqx * zhekou;
double wqpc = wqp * zhekou;
boolean mk = tsc < 100;
boolean ju = wqxc < 100;
boolean lk = wqpc < 100;
System.out.println("T恤折扣价低于100吗?" + mk);
System.out.println("网球鞋折扣价低于100吗?" + ju);
System.out.println("网球拍折扣价低于100吗?" + lk);
}
}
swith作业类:
import java.util.Scanner;
public class LoginMenu{
public static void main(String[]args){
Scanner input=new Scanner(System.in);
System.out.println("请输入消费金额:");
double asd=input.nextDouble();
System.out.println("******优惠活动公告!!*****
");
System.out.println("1:满50元,加2元换购百事可乐一瓶");
System.out.println("2:满100元,加3元换购500ml可乐一瓶");
System.out.println("3:满100元,加10元换购5公斤面粉");
System.out.println("4:满200元,加10元可换购一个苏泊尔炒菜锅");
System.out.println("5:满200元,加20元可换购欧莱雅爽肤水一瓶");
System.out.println("0:不换购");
System.out.println("*****************************
");
if(asd>=200){
System.out.println("您可以换购以下商品");
System.out.println("1:满50元,加2元换购百事可乐一瓶");
System.out.println("2:满100元,加3元换购500ml可乐一瓶");
System.out.println("3:满100元,加10元换购5公斤面粉");
System.out.println("4:满200元,加10元可换购一个苏泊尔炒菜锅");
System.out.println("5:满200元,加20元可换购欧莱雅爽肤水一瓶");
System.out.println("0:不换购");
System.out.println("请选择:");
int tgh=input.nextInt();
switch(tgh){
case 1:
System.out.println("本次消费总金额:"+(asd+2)+"元");
System.out.println("成功换购:500ml可乐一瓶。");
break;
case 2:
System.out.println("本次消费总金额:"+(asd+3)+"元");
System.out.println("成功换购:500ml可乐一瓶。");
break;
case 3:
System.out.println("本次消费总金额:"+(asd+10)+"元");
System.out.println("成功换购:5公斤面粉。");
break;
case 4:
System.out.println("本次消费总金额:"+(asd+10)+"元");
System.out.println("成功换购:一个苏泊尔炒菜锅。");
break;
case 5:
System.out.println("本次消费总金额:"+(asd+20)+"元");
System.out.println("成功换购欧莱雅爽肤水一瓶。");
break;
default :
System.out.println("本次消费总金额:" + asd + "元");
break;
}
}else if(asd>=100){
System.out.println("您可以换购以下商品");
System.out.println("1:满50元,加2元换购百事可乐一瓶");
System.out.println("2:满100元,加3元换购500ml可乐一瓶");
System.out.println("3:满100元,加10元换购5公斤面粉");
System.out.println("0:不换购");
System.out.println("请选择:");
int tgh=input.nextInt();
switch(tgh){
case 1:
System.out.println("本次消费总金额:"+(asd+2)+"元");
System.out.println("成功换购:500ml可乐一瓶。");
break;
case 2:
System.out.println("本次消费总金额:"+(asd+3)+"元");
System.out.println("成功换购:500ml可乐一瓶。");
break;
case 3:
System.out.println("本次消费总金额:"+(asd+10)+"元");
System.out.println("成功换购:5公斤面粉。");
break;
default :
System.out.println("本次消费总金额:" + asd+ "元");
break;
}
}else if(asd>=50){
System.out.println("您可以换购以下商品");
System.out.println("1:满50元,加2元换购百事可乐一瓶");
System.out.println("0:不换购");
System.out.println("请选择:");
int tgh=input.nextInt();
switch(tgh){
case 1:
System.out.println("本次消费总金额:"+(asd+2)+"元");
System.out.println("成功换购:500ml可乐一瓶。");
break;
default :
System.out.println("本次消费总金额:" + asd + "元");
break;
}
}
}
}