if if else else 多选的理解
package com.fqs.test; import java.util.Scanner; public class hello { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.print("请在键盘输入1到100间的儿子成绩"); int my_num=sc.nextInt();//键盘接收输入的值放到my_num中 if(my_num<=0||my_num>100){ System.out.print("不合法"); } else if(my_num<80){ System.out.print("打一顿"); } else if(my_num<90&&my_num>=80){ System.out.print("变形金刚"); } else if(my_num<100&&my_num>=90){ System.out.print("游乐场一日游"); } else{ System.out.print("自行车一辆"); } } }
会员购买商品享受折扣
package com.fqs.test; import java.util.Scanner; public class hello { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.print("请在键盘输入 会员等级"); int my_num=sc.nextInt();//键盘接收输入的值放到my_num中 int price=1000; if(my_num<=0||my_num>4){ System.out.print("不是会员,没有折扣"+price); } else if(my_num==3){ System.out.print("3级会员折扣后价格:"+price*0.9); } else if(my_num==2){ System.out.print("2级会员折扣后价格:"+price*0.8); } else { System.out.print("1级会员折扣后价格:"+price*0.7); } } }