1.编写一个随机生成 10个 0(包括) 到 100 之间的随机正整数
package asdf;
import java.util.Random;
public class QWERT {public static void main(String[] args) {
Random r1 = new Random();
System.out.print("随机数为:");
for(int i=1;i<=10;i++) {
int x = r1.nextInt(100);
System.out.print(" "+x);
}
}
}
2.通过电子版教材或者视频,自学Date类和SimpleDateFormat类,用以下格式输出
系统当前时间
公元2020年05月28日:今天是2020年的第149天,星期四
package asdf;
import java.text.SimpleDateFormat;
import java.util.Date;
public class QWERT {public static void main(String[] args) {
SimpleDateFormat d=new SimpleDateFormat("Gyyyy年MM月dd日:今天是yyyy年的第D天,E");
Date s=new Date();
String sc=d.format(s);
System.out.println(sc);
}}
3.输入一个邮箱地址,判断是否合法.如果合法,输出用户名.
合法:必须包含@ 和 . 并且.在@的后面 (用indexof)
用户名: 例如 dandan@163.com 用户名为dandan (用subString)
package asdf;
import java.util.Scanner;
public class QWERT {public static void main(String[] args) {
// TODO Auto-generated method stub
show();
}
private static void show() {
System.out.println("请输入邮箱编码:");
Scanner input=new Scanner(System.in);
String A=input.next();
boolean result = A.isEmpty();
if (true) {
int c =A.indexOf("@");
int b =A.indexOf(".");
if (b==c+1) {
System.out.println("输入合法!");
String s1=A.substring(0, c);
System.out.println(s1);
}else {
System.out.println("输入不合法!");
}
}else {
System.out.println("输入为空!");
}
}
}
原文:https://www.cnblogs.com/zxnm1234/p/12985559.html