2021-03-24

这篇博客介绍了使用Java进行日期处理,包括判断某年某月的天数,考虑了闰年的条件。此外,还涉及数值交换的实现,以及一个有趣的故事模拟了婚姻与彩礼价格的计算。最后,博客展示了字符串比较、大小写转换、随机数生成用于模拟抽奖以及比较三个随机数大小的算法。
摘要由CSDN通过智能技术生成

package char03;
import java.util.*;
public class review {
public static void main (String [] args){
//判断某年某月有多少天
//大月有1、3、5、7、8、10、12 小月有4、6、9、11月
//闰年2月有29天 平年2月有28天 闰年判断能被四整除但不能被100整除,或者被400整除
Scanner input = new Scanner(System.in);
int year,month,day;
System.out.println(“请输入某年份”);
year =input.nextInt();
System.out.println(“请输入某月份”);
month =input.nextInt();

    switch(month){
        case 1: case 3: case 5: case 7: case 8: case 10: case 12:
            day = 31;
            System.out.println("该年月有"+day+"天");
            break;
        case 4: case 6: case 9: case 11:
            day = 30;
            System.out.println("该年月有"+day+"天");
    }
    if((year%4==0&&year%100!=0)||year%400==0){
        day = 29;
        System.out.println("该年月有"+day+"天");
    }
    else{
        day = 28;
        System.out.println("该年月有"+day+"天");
    }


   //交换值
    int left =3,right =5,swap =0;
    System.out.println("left="+left+"right="+right);
    swap = left;
    left = right;
    right = swap;
    System.out.println("left="+left+"right"+right);




    //嫁女儿的故事
    //身高每欠一公分,彩礼加3万
    //体重每欠或超出一斤,彩礼加2万
    //每结一次婚,彩礼加40万

    final double HEIGHT =1.80;final double WEIGHT_TOP =160,WEIGHT_BOTTOM = 140,BRIDE_PRICE=88;
    final char MARRIED = '否';//标准

    double height =198,weight =154,married_times=1;boolean married =false;
    //一个男人的个人信息


    double height_price = height>=HEIGHT?0:height*10;
    double weight_price = (weight<=WEIGHT_TOP&&weight>=WEIGHT_BOTTOM)?0:Math.abs((weight<WEIGHT_BOTTOM)?WEIGHT_BOTTOM:WEIGHT_TOP)*2;
    double married_price = (married?0:married_times*40)+BRIDE_PRICE;
    double bride_price = height_price+weight_price+married_price;
    System.out.println("需要花费"+bride_price+"万元人民币");




    //字符串比较大小
    String a = "a",b = "b";
    int rst = a.compareTo(b);
    if(rst>0){
        System.out.println("a>b");
    }else if{
        System.out.println("a<b");
    }else{
        System.out.println("a=b");
    }


    //大小写转换
    // System.out.println("aBcdEfgh".toLowerCase());

    //中奖
    Random rand = new Random();
    int fir = 10+rand.nextInt(89);
    int sec = 10+rand.nextInt(89);
    int tir = 10+rand.nextInt(89);
    int num = 10+rand.nextInt(89);


    if(num==fir){
        System.out.println("恭喜你得了一等奖");
    }else if(num==sec){
        System.out.println("恭喜你得了二等奖");
    } else if(num==tir){
        System.out.println("恭喜你得了三等奖");
    }else{
        System.out.println("你没中奖");
    }




    //          随机输入三个数,比较其大小
    Random rand = new Random();
    int a = 10+rand.nextInt(89);
    int b= 10+rand.nextInt(89);
    int c = 10+rand.nextInt(89);

    int min,mid,max=0;
      if(a>b){
        if(a>c){
            if(b>c){
                max = a;
                mid = b;
                min = c;
            }else{
                max = a;
                mid = c;
                min = b;
            }


        }else{
            max = c;
            mid = a;
            min = b;

        }
    }
    else{
        if(b>c){
            if(a>c){
                max = b;
                mid = a;
                min = c;
            }else{
                max = b;
                mid = c;
                min = a;
            }
        }else{
            max = c;
            mid = b;
            min = a;

        }
    }
    System.out.println("max="+max+"mid="+mid+"min="+min);

   
   
   
    int temp;
    if(a<b){
        temp =a;
        a = b;
        b = temp;

     }
    if (a<c){
        temp = a;
        a = c;
        c = temp;
    }
    if (b<c){
        temp = b;
        b = c;
        c = temp;
    }
    System.out.println("max="+a+"mid="+b+"min="+c);



    


}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值