第十六次作业

package ydy57;
import java.util.Random;

public class test {

    public static void main(String args[]) {
        
         int a[] = new int[10];
            Random r = new Random();
            for (int i = 0; i < a.length; i++) {
                a[i] = r.nextInt(100);
            }
            for (int i = 0; i < a.length; i++) {
                System.out.println(a[i]);
            }

        }

    
}
            
   

 

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

package ydy57;
import java.text.SimpleDateFormat;
import java.util.Date;
public class test {

    public static void main(String args[]) {
        
          Date c = new Date();
            SimpleDateFormat a1 = new SimpleDateFormat("Eyyyy年MM月dd日");
            SimpleDateFormat a2 = new SimpleDateFormat("今天是Eyyyy年的第 D 天 ,E");
            System.out.println(a1.format(c));
            System.out.println(a2.format(c));
     

        }

    
}
            
    



   

 

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

package ydy57;
import java.util.Scanner;
public class test {

    public static void main(String args[]) {
        
           Scanner input = new Scanner(System.in);
            System.out.print("请输入合法的邮箱:");
            String s = input.nextLine();
            int a = 0;
            int b = 0;
            int x = 0;
            int y = 0;
            for (int i= 0; i < s.length() - 1; i++) {
                String str = s.substring(i, i + 1);
                if (str.equals("@")) {
                    a++;
                    x = i;
                }
                if (str.equals(".")) {
                   b++;
                    y = i;
                }
            }
            if (a == 1 &&b == 1 && x < (y - 1) && x != 0 && y != s.length() - 1) {
               s.endsWith("@qq.com");
                System.out.println("合法");
            } else {
                System.out.println("不合法");
            }
            String s1 = s.substring(0, s.indexOf("@"));
            System.out.println("用户名是:"+s1);
     
        }
    
}                

 

posted @ 2020-05-28 11:23  大元128  阅读(148)  评论(0编辑  收藏  举报