标签:姓名 system.in input size java can visit next .sh
import java.util.Scanner;
public class Visitor {
String name;
int age;
public void show() {
Scanner input = new Scanner(System.in);
while(!"n".equals(name)) {
if(age>=18&&age<=60) {
System.out.println(name+"您的年龄为:"+age+
"门票价格为20元\n");
}else {
System.out.println(name+"您的年龄为:"+age+
"门票免费\n");
}
System.out.print("请输入姓名");
name=input.next();
if(!"n".equals(name)) {
System.out.print("请输入年龄");
age=input.nextInt();
}
}
System.out.println("退出程序");
}
}
import java.util.Scanner;
public class InitialVistor {
public static void main(String[] args) {
Scanner input =new Scanner(System.in);
Visitor vis =new Visitor();
System.out.print("请输入姓名:");
vis.name=input.next();
System.out.print("请输入您的年龄:");
vis.age=input.nextInt();
vis.show();
}
}
标签:姓名 system.in input size java can visit next .sh
原文地址:https://www.cnblogs.com/F017/p/9776118.html