首页 > 编程语言 > 详细

Java_20.5.28

时间:2020-05-28 14:04:36      阅读:53      评论:0      收藏:0      [点我收藏+]

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

package ffeng;

import java.util.Random;

public class Ran {
    public static void main(String[] args) {
        Random r=new Random();
        int[] n=new int[10];
        for(int i=0;i<n.length;i++) {
            n[i]=0+r.nextInt(101);
            System.out.print(n[i]+" ");
        }
    }
}

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

package ffeng;

import java.text.SimpleDateFormat;
import java.util.Date;

public class 格式化日期 {
    public static void main(String[] args) {
        Date now = new Date(); // 创建一个Date对象,获取当前时间
        // 指定格式化格式
        SimpleDateFormat f = new SimpleDateFormat("公元" + "yyyy年 MM月dd日:" + "今天是" + "yyyy年的第D天,E。");
        // yyyy:年份;
        // MM:月份;
        // dd:日期;
        // D:一年中的第几天;
        // E:星期;
        // HH:小时;
        // mm:分钟;
        // ss:秒;
        System.out.println(f.format(now)); // 将当前时间袼式化为指定的格式
    }
}

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

package ffeng;

import java.util.Scanner;

public class West {

    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        System.out.println("请输入一个邮箱地址");
        String email=s.next();
        int i=email.indexOf("@");
        int j=email.indexOf(‘.‘);
        if(i!=0&&j>i) {
            System.out.println("合法");
            String r=email.substring(email.indexOf(0)+
1,email.indexOf(‘@‘));
            System.out.println("用户名: "+r);
        }else {
            System.out.println("不合法");
        }
    }
}

 

Java_20.5.28

原文:https://www.cnblogs.com/Fzippoby/p/12980404.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!