【无标题】

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.Month;
import java.time.Period;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.Random;
import java.util.Scanner;

public class test {
    public static void main(String[] args) {


//        9.	查看系统的配置信息和虚拟机的状态信息
        // 输出系统配置信息
        System.out.println("系统配置信息:");
        System.getProperties().list(System.out);

        // 输出虚拟机状态信息
        Runtime runtime = Runtime.getRuntime();
        System.out.println("虚拟机状态信息:");
        System.out.println("可用处理器核心数:" + runtime.availableProcessors());
        System.out.println("总内存:" + runtime.totalMemory());
        System.out.println("可用内存:" + runtime.freeMemory());
        System.out.println("最大可用内存:" + runtime.maxMemory());


//        10.	比5.6大的最小整数和比它小的最大整数
        // 完成比5.6大的最小整数和比它小的最大整数
        double targetNumber = 5.6;

        // 找到比5.6大的最小整数
        int minInteger = (int) Math.ceil(targetNumber);
        System.out.println("比" + targetNumber + "大的最小整数:" + minInteger);

        // 找到比5.6小的最大整数
        int maxInteger = (int) Math.floor(targetNumber);
        System.out.println("比" + targetNumber + "小的最大整数:" + maxInteger);


//        11.	产生1-100的随机整数 Random.nextInt(100)+1
        // 生成1到100之间的随机整数
        Random random = new Random();
        int randomNumber = random.nextInt(100) + 1;
        System.out.println("1到100之间的随机整数:" + randomNumber);


//        12.	以年月日时分秒显示当前系统时间
        // 获取当前系统时间
        Date currentDate = new Date();

        // 格式化时间为年月日时分秒
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String formattedDate = dateFormat.format(currentDate);

        // 输出格式化后的时间
        System.out.println("当前系统时间:" + formattedDate);
//        13.	计算距离下课的分钟数,计算你还有多少天过生日

        // 获取当前时间和下课时间
        LocalTime currentTime = LocalTime.now();
        LocalTime endOfClassTime = LocalTime.of(15, 30); // 设置下课时间,这里假设下课时间为下午3点30分

        // 计算距离下课的分钟数
        long minutesUntilEndOfClass = currentTime.until(endOfClassTime, ChronoUnit.MINUTES);
        System.out.println("距离下课还有:" + minutesUntilEndOfClass + " 分钟");
        // 获取当前日期和生日
        LocalDate currentDate1 = LocalDate.now();
        LocalDate birthday = LocalDate.of(currentDate1.getYear(), Month.SEPTEMBER, 5); // 假设生日在每年的12月31日

        // 计算距离生日还有多少天
        Period daysUntilBirthday = Period.between(currentDate1, birthday);
        int days = daysUntilBirthday.getDays();
        if (days < 0) {
            // 如果今年的生日已经过去了,则计算到明年生日的天数
            birthday = birthday.plusYears(1);
            daysUntilBirthday = Period.between(currentDate1, birthday);
            days = daysUntilBirthday.getDays();
        }
        System.out.println("距离生日还有:" + days + " 天");


//        14.	计算字符串“123”与整数值25的和
        // 创建字符串
        String myString = "abCD123";
        System.out.println("字符串内容:" + myString);
        // 提取字符串中的数字部分
        String numericPart = myString.replaceAll("[^0-9]", ""); // 过滤非数字字符

        // 将提取的数字字符串转换为整数
        int numericValue = Integer.parseInt(numericPart);

        // 计算与整数值25的和
        int sum = numericValue + 25;
        System.out.println("字符串中的数字与整数值25的和:" + sum);



//        15.	模拟输入用户名,要求用户名由8-16位的字母数字和@符号(3种符号都要存在)构成,且首字母大写。如果匹配则提示用户名合法,否则提示用户名非法。
        // 模拟输入用户名
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入用户名: ");
        String username = scanner.nextLine();

        // 检查用户名是否合法
        if (isValidUsername(username)) {
            System.out.println("用户名合法");
        } else {
            System.out.println("用户名非法");
        }
    }

    private static boolean isValidUsername(String username) {
        // 长度要求为8-16位
        if (username.length() < 8 || username.length() > 16) {
            return false;
        }

        // 首字母大写
        if (!Character.isUpperCase(username.charAt(0))) {
            return false;
        }

        // 必须包含字母、数字和@符号
        boolean hasLetter = false;
        boolean hasDigit = false;
        boolean hasAtSymbol = false;

        for (char ch : username.toCharArray()) {
            if (Character.isLetter(ch)) {
                hasLetter = true;
            } else if (Character.isDigit(ch)) {
                hasDigit = true;
            } else if (ch == '@') {
                hasAtSymbol = true;
            }
        }

        return hasLetter && hasDigit && hasAtSymbol;
    }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值