课后练习4:
package a2;
import java.util.Scanner;
public class C4 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String o;
do {
System.out.println("请输入长度为6的字符串:");
o = input.nextLine();
}while(o.length() != 6);
System.out.println("程序退出,你输入了:"+o);
}
}
课后练习5:
package a2;
import java.util.Scanner;
import org.omg.Messaging.SyncScopeHelper;
public class C5 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
boolean flag = false;
System.out.print("请输入会员生日<月/日:00/00>:");
String birth = input.next();
while(!flag) {
if(Integer.parseInt(birth.substring(0,birth.indexOf('/')))>=1 &&
Integer.parseInt(birth.substring(0,birth.indexOf('/')))<=12 &&
Integer.parseInt(birth.substring(birth.indexOf('/')+1,birth.length()))>=1 &&
Integer.parseInt(birth.substring(birth.indexOf('/')+1,birth.length()))<=31) {
System.out.println("该会员的生日是:"+birth);
flag = true;
}else {
System.out.println("请输入会员生日<月/日:00/00>:");
birth = input.next();
flag = false;
}
}
flag = false;
do {
System.out.println("请输入会员密码<6~10位>:");
String password = input.next();
if((password.length()>=6 && password.length()<=10)) {
System.out.println("该会员的密码是:"+password);
flag = true;
}else {
System.out.println("密码输入形式错误!");
}
}while(!flag);
}
}
课后练习6:
package a2;
import java.util.Random;
import java.util.Scanner;
public class C6 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("请输入会员姓名:");
String name = input.next();
System.out.println("请输入会员性别:");
String sex = input.next();
System.out.println("请输入会员年龄:");
int age = input.nextInt();
System.out.println("创建会员成功:");
System.out.print("会员编号:");
for (int i = 0; i < 4; i++) {
Random num = new Random();
int n = num.nextInt(10);
System.out.print(n);
}
System.out.println("会员详细信息:");
System.out.println(name+"\t"+sex+"\t"+age);
}
}
高级特性 第2章
最新推荐文章于 2020-05-21 18:37:44 发布