Java怎么判断岁数代码 java判断年龄是否成年( 二 )


public class Test {
private static Scanner in = null;
public static String getName(){
String name = "";
in = new Scanner(System.in);
System.out.println("Entername : ");
name = in.nextLine();
return name;
}
public static int getAge(){
int age = 0;
in = new Scanner(System.in);
System.out.println("Enterage : ");
age = in.nextInt();
return age;
}
public static int compareAge( int age1 , int age2){
return age1 - age2;
}
public static void main(String[] args) {
String nameA = getName();
int ageA = getAge();
String nameB = getName();
int ageB = getAge();
int compare = compareAge(ageA,ageB);
if( compare0 ){
System.out.println( nameA +" is order than " + nameB + " by " + compare + "year");
}else if( compare0 ){
System.out.println(nameA +" is younger than " + nameB + " by " + compareAge(ageB,ageA) + " year");
}
}
}
Java怎么判断岁数代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java判断年龄是否成年、Java怎么判断岁数代码的信息别忘了在本站进行查找喔 。

推荐阅读