第十七次作业

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

package snippet;

import java.util.Random;

public class text {
    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 snippet;

import java.text.SimpleDateFormat;
import java.util.Date;

public class text {
    public static void main(String[] args) {
        SimpleDateFormat sdf = new SimpleDateFormat("今年是Gyyyy年MM月dd日");

        Date d = new Date();
        SimpleDateFormat sd = new SimpleDateFormat("今天是Gyyyy年的第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 snippet;

import java.util.Scanner;

import org.omg.Messaging.SyncScopeHelper;

public class text {

    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) {
            S
原文地址:https://www.cnblogs.com/Zzzhqh/p/12983286.html