任务1:
//键盘输入
Scanner sc=new Scanner(System.in);
int age=sc.nextInt();
if(age>18) {
System.out.println("你是一个成年人了");
}
任务2:
System.out.println("---进入程序--3---");
//键盘输入
Scanner sc=new Scanner(System.in);
//循环判断输入的值是否正确
for(;;) {
System.out.println("输入账号和密码,账号和密码一致时可进入程序");
System.out.print("输入账号:");
int account=sc.nextInt();
System.out.print("输入密码:");
int password=sc.nextInt();
if(password==account) {
System.out.println("输入正确");
break;
}
else {
System.out.println("输入错误,请重新输入");
}
任务3:
System.out.println("请输入金额:");
Scanner sc=new Scanner(System.in) ;
int A=sc.nextInt();
if(A>=0&&A<=200000) {
System.out.println("暂时不买车");
}
else if(A>200000&&A<=500000) {
System.out.println("买大众");
}
else if(A>500000&&A<=1000000) {
System.out.println("买奔驰");
}
任务4:
1:空
2:
for (int a = 1; a<100; a++)
{
if(a%10==0) {
System.out.println();
}
System.out.printf("%10d",a);
}
3:空
4:
Scanner sc=new Scanner(System.in);
System.out.println("请输入行数");
int length=sc.nextInt();
//三角形行数循环输出(高)
for(int i=1;i<=length;i++) {
//三角形空白输出,每行循环输出次数
//三角形每行的边,每行多出一个位所以输出次数-1
for(int a=length-i;a>0;a--) {
System.out.print(" ");
}
//输出三角形体
//输出个数为当前行高的两倍减1
for(int b=0;b<2*i-1;b++) {
System.out.print("*");
}
System.out.println();
}
5:空
6:
System.out.print("输入账号:");
int account=sc.nextInt();
Integer account1=account;
System.out.print("输入密码:");
int password=sc.nextInt();
Integer password1=password;
if(password1.toString().length()<6||password1.toString().length()<16&&account1.toString().length()>6||account1.toString().length()<16) {
System.out.println("账号是:"+account+"密码是:"+password);
break;
}
else {
System.out.println("请重新输入账号和密码");
}
7:空