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元
");
}else {
System.out.println(name+"您的年龄为:"+age+
"门票免费
");
}
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();
}
}