The class getter {
private String name;
Private int the age;
Public String getName () {
return this.name;
}
Public void elegantly-named setName (String name) {
this.name=name;
}
Public int getAge () {
Return this. The age;
}
Public void setAge (int age) {
If (age> 0 & amp; & Age<100) {
this.age=age;
} else {
System. Out.println (" illegal input, please input again!" );
return;
}
}
}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
import java.util.Scanner;
Public class test {
Public static void main (String [] args) {
Getter g=new getter ();
Scanner sc=new Scanner(System.in);
System. The out. Println (" please input your name: ");
String s1=sc. NextLine ();
G.s etName (s1);
System. The out. Println (" please enter the age: ");
Int s2=sc. NextInt ();
G.s etAge (s2);
System. The out. Println (g.g etName ());
System. The out. Println (g.g etAge ());
System. The out. Println (" my name is "+ g.g etName () +", "+" I am "+ g.g etAge () +", ");
}
}
CodePudding user response:
Just print the words, and not interrupt program,CodePudding user response:
Return just over current method, namely setAge method, main continues executionCodePudding user response:
If your ide intelligent enough, it will prompt you to 'return' unnecessary, because is the last statement of "void" methodCodePudding user response:
Ide does prompt return unnecessary, if the input error need to terminate the run and wait for the input again, how should do? Thank you very much!