zoukankan      html  css  js  c++  java
  • 5.28第十三周

    1.编写一个随机生成 10个 0(包括) 到 100 之间的随机正整数

    package wyy;
    
    import java.util.Random;
    
    public class Test6 {
        public static void main(String[] args) {
            Random r = new Random();
            for (int i = 1; i <= 10; i++) {
                System.out.print(r.nextInt(101) + ",");
            }
    
        }
    }

    2.通过电子版教材或者视频,自学Date类和SimpleDateFormat类,用以下格式输出
    系统当前时间
    公元2020年05月28日:今天是2020年的第149天,星期四

    package wyy;
    
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    public class Test6 {
        public static void main(String[] args) {
            SimpleDateFormat sdf = new SimpleDateFormat("G年M月d日");
    
            Date d = new Date();
            SimpleDateFormat sd = new SimpleDateFormat("今天是G年的第D天,E");
            String s = sdf.format(d);
            String s1 = sd.format(d);
            System.out.println(s + ":" + s1);
    
        }
    }

    3.输入一个邮箱地址,判断是否合法.如果合法,输出用户名.
    合法:必须包含@ 和 . 并且.在@的后面 (用indexof)
    用户名: 例如 dandan@163.com 用户名为dandan (用subString)

    package wyy;
    
    import java.util.Scanner;
    
    import org.omg.Messaging.SyncScopeHelper;
    
    public class PersonCreate {
    
        public static void main(String[] args) {
            PersonCreate();
        }
    
        private static void PersonCreate() {
            Scanner sc = new Scanner(System.in);
            System.out.println("邮箱:");
            String mail = sc.nextLine();
            // 邮箱地址中不包含@或.
            if (mail.indexOf("@") == -1) {
                System.out.println("邮箱地址中不包含@");
            }
            if (mail.indexOf(".") == -1) {
                System.out.println("邮箱地址中不包含.");
            }
            // 邮箱地址中含有多了@或.
            int a = 0;
            for (int i = 0; i < mail.length(); i++) {
                if (mail.charAt(i) == '@') {
                    a++;
                }
            }
            if (a > 1) {
                System.out.println("邮箱地址中含有多余的@");
            }
            int b = 0;
            for (int i = 0; i < mail.length(); i++) {
                if (mail.charAt(i) == '.') {
                    b++;
                }
            }
            if (b > 1) {
                System.out.println("邮箱地址中含有多余的.");
            }
            // 邮箱地址中.出现在@的前面
            int index = mail.indexOf('@');
            int index1 = mail.indexOf('.');
            if (index1 <= index) {
                System.out.println("邮箱地址中.出现在@的前面");
            }
            // 用户名里有其他字符
            String R = "\w + @ \w +\.\w{2,3} ";
            if (!(mail.matches(R))) {
                System.out.println("用户名里有其他字符");
            }
    
        }
    
    }
  • 相关阅读:
    在画图时添加中文
    legend图例
    数组的拼接
    将多维数组改为一维数组
    ChinaCock扫描控件介绍-使用TCCBarcodeScanner引起app闪退
    ChinaCock打印控件介绍-TCCFujitsuPrinter实现蓝牙针式打印
    用NetHttpClient执行Post操作遇到的问题
    【转】FireMonkey ListView 自动计算行高
    基于MQTT的串口数据转发器
    kbmMW均衡负载与容灾(1)
  • 原文地址:https://www.cnblogs.com/WangYYY/p/12987252.html
Copyright © 2011-2022 走看看