zoukankan      html  css  js  c++  java
  • 第十三周上机作业

    import java.util.Random;
    //1.编写一个随机生成 10个 0(包括) 到 100 之间的随机正整数。
    public class test {
    	public static void main(String[] args) {
    		Random r = new Random();
    		for (int i = 0; i < 10; i++) {
    			System.out.println("第" + (i + 1) + "个随机数");
    			int j = r.nextInt(101);
    			System.out.println(j);
    		}
    	}
    }
    

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

    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.Random;
    //2.Date类和SimpleDateFormat类,用以下格式输出
    //系统当前时间
    //公元2020年05月28日:今天是2020年的第149天,星期四
    public class test2 {
    	public static void main(String[] args) {
    		SimpleDateFormat sdf = new SimpleDateFormat("Gyyyy年MM月dd日 E HH:mm:ss");
    		Date date = new Date();
    		String format = sdf.format(date);
    		System.out.println(format);
    	}
    }    
    

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

    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.Random;
    import java.util.Scanner;
    //3.输入一个邮箱地址,判断是否合法.如果合法,输出用户名.
    //合法:必须包含@ 和 . 并且.在@的后面 (用indexof)
    //用户名: 例如 dandan@
    public class test3 {
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		System.out.println("输入一个邮箱地址");
    		String string = sc.next();
    		if (string.contains("@.") == true) {
    			int indexOf = string.indexOf("@.");
    			String substring = string.substring(0, indexOf);
    			System.out.println(substring);
    		} else {
    			System.out.println("邮箱不合法");
    		}
    	}
    }
    

      

     
  • 相关阅读:
    安装mongoDB时,总是报错,启动不了
    koa2路由
    异步操作async await
    nodeJs koa-generator脚手架
    nodeJs学习-19 个人博客案例-(1)数据字典
    nodeJs学习-18 mysql数据库了解
    nodeJs学习-17 博客案例
    nodeJs学习-16 数据字典示例
    前端图片压缩后,文件流上传
    Linux用户名显示-bash-4.1$快速排查
  • 原文地址:https://www.cnblogs.com/overCROSS/p/12979398.html
Copyright © 2011-2022 走看看