biu~~~

导航

 

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

 1 import java.util.Random;
 2 
 3 public class R{
 4     public static void main(String[] args) {
 5         // TODO Auto-generated method stub
 6         Random r = new Random();
 7         for (int j = 0; j < 10; j++) {
 8             int i = r.nextInt(100);
 9             System.out.println(i);
10         }
11 
12     }
13 }

 

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

 1 package R;
 2 
 3 import java.text.ParseException;
 4 import java.text.SimpleDateFormat;
 5 import java.util.Date;
 6   
 7 public class zuoye {
 8   
 9  public static void main(String[] args) throws ParseException {
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   
18 }

 

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

 1 package R;
 2 
 3 import java.util.Scanner;
 4 public class zuoye{
 5     public static void  main (String[]args) {
 6         //TODO Auto-generated method stub
 7         Scanner input=new Scanner(System.in);
 8         System.out.print("请输入合法的新浪邮件:");
 9         String str =input.nextLine();
10         int count=0;
11         int count2=0;
12         int x=0;
13         int y=0;
14         for(int j=0;j<str.length()-1;j++) {
15             String str1=str.substring(j,j+1);
16             if(str1.contentEquals("@")) {
17                 count++;
18                 x=j;
19             }
20             if(str1.contentEquals(".")) {
21                 count2++;
22                 y=j;
23             }
24         }
25         if(count==1&&count2==1&&x<(y-1)&&x!=0&&y!=str.length()-1) {
26             str.endsWith("@sina.com");
27             System.out.println("合法");
28         }else {
29             System.out.println("不合法");
30         }
31     }
32 }

 

posted on 2020-05-28 12:18  biu~~~  阅读(115)  评论(0编辑  收藏  举报