题解 | #验证年龄#
验证年龄
http://www.nowcoder.com/practice/fdb94493ebc34eef8d9b01dea47685b9
public class Main {
public static void main(String[] args) {
Person p = new Person();
Scanner scanner = new Scanner(System.in);
while (scanner.hasNextInt()) {
int age = scanner.nextInt();
p.setAge(age);
if(p.getAge()<0){
System.out.println("0");
}
else if(p.getAge()>200){
System.out.println("200");
}
else{
System.out.println(p.getAge());
}
}
}
}
class Person {
private int age;
public Person(){
}
public void setAge(int age)
{
this.age=age;
}
public int getAge(){
return age;
}
//write your code here......
}