日期:2014-05-20 浏览次数:20814 次
import java.util.Scanner;
public class oop3
{
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();
}
}
import java.util.Scanner;
class Visitor
{
String name;
int age;
public void show()
{
Scannner 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("请输入姓名:");
if(!"n".equals(name)){
System.out.print("请输入年龄:");
age=input.nextInt();
}
}
System.out.print("退出");
}
}