第十三周作业

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

 1 package yyy ;
 2 
 3 import java.util.Arrays;
 4 import java.util.Random;
 5 import java.util.Scanner;
 6 
 7 public class suijishu {
 8 
 9     public static void main(String[] args) {
10 
11         int arr[] = new int[11];
12         Random r = new Random();
13         for (int i = 0; i < 10; i++) {
14             System.out.println(r.nextInt(100) + 1);
15         }
16     }
17 
18 }

2.Date类和SimpleDateFormat类,用以下格式输出
系统当前时间
公元2020年05月28日:今天是2020年的第149天,星期四

 1 package yyy;
 2 
 3 import java.text.ParseException;
 4 import java.text.SimpleDateFormat;
 5 import java.util.Date;
 6 
 7 public class gongyuan {
 8 
 9     public static void main(String[] args) {
10         // TODO Auto-generated method stub
11         SimpleDateFormat CeshiFmt0 = new SimpleDateFormat("Gyyyy年MM月dd日");
12         SimpleDateFormat CeshiFmt5 = new SimpleDateFormat("今天是Gyyyy年的第 D 天 ,E");
13         Date now = new Date();
14         System.out.println(CeshiFmt0.format(now));
15         System.out.println(CeshiFmt5.format(now));
16     }
17 }

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

 1 package yyy;
 2 
 3 import java.text.SimpleDateFormat;
 4 import java.util.Random;
 5 import java.util.Scanner;
 6 
 7 public class email {
 8     public static void main(String[] args) {        
 9         Scanner s= new Scanner(System.in);
10         System.out.println("输入邮箱地址");
11         String string = s.next();
12         if(string.contains("@.") ==true) {
13             int indexOf = string.indexOf("@.");
14             String substring = string.substring(0, indexOf);
15             System.out.println(substring);
16         }else {
17             System.out.println("邮箱不合法");
18         }    
19     }  
20 }

 

posted @ 2020-05-29 10:43  就这水平?  阅读(87)  评论(0编辑  收藏  举报