[java]代码库
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+",免费");
}
}
}
}
public class youren {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
Visitor v = new Visitor();
System.out.print("请输入姓名:");
v.name = input.next();
System.out.print("请输入年龄:");
v.age = input.nextInt();
v.show();
}
}//源代码片段来自云代码http://yuncode.net