java 条件判断语句 If-else的练习

java 条件判读语句的练习

import java.util.Scanner
class IfTest2{

	public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
      //考试得分等级判断 
       System.out.println("请输入考试得分");

	   int score = scan.nextInt();
	   if(score < 0 || score > 100){
	   System.out.println("数据非法");
	   }else if(score == 100){
		System.out.println("满分");
	   }else if(score > 80 && score <= 99){
		System.out.println("优秀");
	   }else if(score >=60 && score <= 80){
		System.out.println("及格");
	   }else{
		System.out.println("不及格");
	   }

	   //狗子与人的年纪换算
       System.out.println("请输入狗子的年纪");
       int dogAge = scan.nextInt();
	   if(dogAge < 0 ){
	   System.out.println("狗子还没出生");
	   }else if(dogAge >= 0 && dogAge <=2){
	   System.out.println("狗子现在相当于人的年龄是" + dogAge * 10.5 + "岁。");
	   }else if(dogAge > 2 && dogAge < 30){
	   System.out.println("狗子现在相当于人的年龄是" +( ( (dogAge -2) * 4) + 21 )+ "岁。");
	   }else{
	   System.out.println("绝世神狗");
	   }

      //彩票中奖判断,需要使用随机数
      //程序随机产生一个两位数彩票,范围[10,100),用户输入一个两位整数进行匹配度判断
      //随机数可以通过Math.random()调用范围是[0.0,1.0) ,输出类型是double,需要强转成int

	  int value =(int)(Math.random()*90 + 10);//将集合0-1映射为10-100
      int valueShi = value / 10;
	  int valueGe = value % 10;
	  System.out.println("请输入一个两位整数,范围从10到99");
	  int guess = scan.nextInt();
	  int guessShi = guess / 10;
	  int guessGe = guess % 10;

	  if(value == guess){
		System.out.println("特等奖");
	  }else if(valueGe == guessShi && valueShi == guessGe){
        System.out.println("一等奖");
	  }else if(valueShi == guessShi || valueGe == guessGe){
        System.out.println("二等奖");
	  }else if(valueShi == guessGe || valueGe == guessShi){
        System.out.println("三等奖");
	  }else{
		System.out.println("很遗憾,没有中奖");
	  }
        System.out.println("本期中奖号码为" + value);


     //满足三个条件可以成为商店白金会员,满足两个成为黄金会员,满足一个成为青铜会员1,会员等级超过3 2,用户卡上余额超过1000 3,是否是商店股东之一
      System.out.println("请输入你的会员等级");
	  int rank = scan.nextInt();
	  System.out.println("请输入你的购物卡余额");
	  double money = scan.nextDouble();
	  System.out.println("请输入你是否为股东之一,填写是/否");
	  String shareHolder1 = scan.next();
	  boolean shareHolder = shareHolder1.equals("是");

	  if(rank >=3 && money >= 1000 && shareHolder == true){
	//或者写成if(rank >=3 && money >= 1000 && shareHolder1.equals("是") == true){
	  System.out.println("恭喜您成为白金会员");
	  }else if(rank >=3 ^ money >= 1000 ^ shareHolder == true){
	  System.out.println("恭喜您成为青铜会员");
	  }else if(rank >=3 || money >= 1000 || shareHolder == true){
	  System.out.println("恭喜您成为黄金会员");
	  }else{
	  System.out.println("很遗憾,条件不符合要求");
	  }

你可能感兴趣的:(java,学习笔记)