zoukankan      html  css  js  c++  java
  • java5.28

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

     1 package Pro1;
     2 import java.util.Random;
     3 public class Test {
     4     public static void main(String[] args) {
     5         Random r = new Random();
     6         for (int j = 0; j < 10; j++) {
     7             int i = r.nextInt(100);
     8             System.out.println(i);
     9         }
    10 
    11     }
    12 }

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

     1 package Pro2;
     2 import java.text.ParseException;
     3 import java.text.SimpleDateFormat;
     4 import java.util.Date;
     5 public class Test {
     6     public static void main(String[] args) throws ParseException {
     7         SimpleDateFormat CeshiFmt0 = new SimpleDateFormat("Gyyyy年MM月dd日");
     8         SimpleDateFormat CeshiFmt5 = new SimpleDateFormat("今天是Gyyyy年的第 D 天 ,E");
     9         Date now = new Date();
    10         System.out.println(CeshiFmt0.format(now));
    11         System.out.println(CeshiFmt5.format(now));
    12     }
    13 }

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

     1 package Pro3;
     2 import java.util.Scanner;
     3 public class Test {
     4     public static void main(String[] args) {
     5         Scanner input = new Scanner(System.in);
     6         System.out.print("请输入合法的邮箱:");
     7         String str = input.nextLine();
     8         int count = 0;
     9         int count2 = 0;
    10         int x = 0;
    11         int y = 0;
    12         for (int j = 0; j < str.length() - 1; j++) {
    13             String str1 = str.substring(j, j + 1);
    14             if (str1.equals("@")) {
    15                 count++;
    16                 x = j;
    17             }
    18             if (str1.equals(".")) {
    19                 count2++;
    20                 y = j;
    21             }
    22         }
    23         if (count == 1 && count2 == 1 && x < (y - 1) && x != 0 && y != str.length() - 1) {
    24             str.endsWith("@163.com");
    25             System.out.println("合法");
    26         } else {
    27             System.out.println("不合法");
    28         }
    29     }
    30 }
  • 相关阅读:
    spring cloud微服务docker启动
    docker安装mysql5.7
    Spring Boot CommandLineRunner的使用
    IDEA Java 源发行版 8 需要目标发行版 1.8
    Centos6.5安装Python2.7.9
    Hive在drop表的时候报错
    反向读取Mysql数据库表结构到PowerDesigner中
    SpringCloud与Consul集成实现负载均衡
    Mac系统安装和卸载brew包管理
    Consul集群搭建
  • 原文地址:https://www.cnblogs.com/qq1123514689/p/12982275.html
Copyright © 2011-2022 走看看