-->
当前位置:首页 > 题库

PROGRAMMING:numbered

Luz5年前 (2021-05-10)题库511
Fill in the blanks. According to the requirements of the title, improve the following code. Please submit the complete code.
"50 this year, 18 next year" is a good wish. People can only grow in age.
The setage method of the person class is used to update the age.
If the new age is younger than the original age, output B means abnormal, otherwise output a means normal.

import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int age;
age = in.nextInt();
Person p = new Person(age);
age = in.nextInt();
try{
p.setAge(age);
}catch(AgeException e){
}
}
}
class Person{
int age;
public Person(int age){
this.age = age;
}
public void setAge(int age) throws AgeException {
if(this.age <= age){
this.age = age;
}else{
throw new AgeException();
}
}
}
class AgeException extends Exception{
}

###Input format:
Enter two positive integers a and B with absolute values no more than 100 in one line.
###Output format:
Output a character a or B on a line.
###Input example:
```in
50 18
```
###Output example:
```out
B
```






answer:If there is no answer, please comment