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("邮箱不合法");
    		}
    	}
    }
    

      

     
  • 相关阅读:
    ModelForm详解
    form中choice从数据库实时更新
    django-form字段和插件widgets速查
    Form生成的label标签详解
    form+ajax实现验证
    微分方程的解
    easyui中连接按钮样式
    easyui中设置开始日期只能选择比结束日期小的日期,js代码获取日期的值
    三目表达式问题
    easyui中在formatter: function (value, row,index) {中添加删除方法
  • 原文地址:https://www.cnblogs.com/overCROSS/p/12979398.html
Copyright © 2011-2022 走看看