题解 | #验证年龄#
验证年龄
https://www.nowcoder.com/practice/fdb94493ebc34eef8d9b01dea47685b9
import java.util.Scanner; 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); System.out.println(p.getAge()); } } } class Person { private int age; public void setAge(int x){ //无需多言 this.age=x<0?0:x>200?200:x; } public int getAge(){ return this.age; } //write your code here...... }