十三周上机作业

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

package sgs;
import java.util.Random;
public class Text1 {
    public static void main(String[] args) {
        for (int i = 1; i < 11; i++) {
            Random r=new Random();
            int a=r.nextInt(100);
            System.out.print(a+" ");
        }
    }

}

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

package sgs;
import java.text.*;
import java.util.*;
public class Text2 {
    public static void main(String[] args) throws Exception {
        SimpleDateFormat sdf=new SimpleDateFormat("Gyyyy年MM月dd日:今天是yyyy年的第D天,E");
        System.out.println(sdf.format(new Date()));
    }

}

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

package sgs;
import java.util.Scanner;
public class Text3 {
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        System.out.println("请输入邮箱:");
        String a=input.next();
        if(a.contains("@") ==true||a.contains(".") ==true) {
            int a1=a.indexOf("@");
            int a2=a.indexOf(".");
           if (a1<a2){
               String substring = a.substring(0, a1);
               System.out.println(substring);
           }else{
               System.out.println("邮箱不合法");
           }
        }else {
            System.out.println("邮箱不合法");
        }
        
    }

}

 

posted @ 2020-05-28 11:46  樊一丁  阅读(148)  评论(0编辑  收藏  举报