import java.util.Scanner; //导包
public class Person {
public String name;
public int age;
/**
* 用来循环接收用户输入,然后判断年龄
*/
public void show(){
Scanner input=new Scanner(System.in);
System.out.println("请输入姓名:");
name=input.next();
//1.循环
while(!name.equals("n")){
System.out.println("请输入年龄:");
age=input.nextInt();
//2.判断
if(age>=18&&age<=60){
System.out.println("门票20元");
}else{
System.out.println("门票免费");
}
System.out.println("请输入姓名:");
name=input.next();
}
System.out.println("程序结束!");
}
}
public static void main(String[] args){
Person person =new Person(); //创建一个Person类的对象 类的实例化的过程
person.show();
}
原文地址:https://www.cnblogs.com/xiao-ran/p/9775865.html
时间: 2024-11-05 21:59:49