62,614
社区成员
发帖
与我相关
我的任务
分享
import java.util.*;
public class TestAge {
public static void main(String[] args) {
String InitialName,InputName,maxName = null,minName = null,StopInput;
int InitialAge,InputAge = 0,maxAge,minAge;
Scanner stdin = new Scanner(System.in);
boolean equals;
System.out.println("Please enter the name : ");
InitialName = stdin.next();
maxName=minName=InitialName;
System.out.println("Please enter the age of this person : ");
InitialAge = stdin.nextInt();
maxAge=minAge=InitialAge;
while(true){ //我想主要是在这里可能要改,但我实在想不到更好的方法了,已经尝试很多次了
System.out.println("Please enter the name : ");
InputName = stdin.next();
if(InputName.equalsIgnoreCase("quit")) break;
System.out.println("Please enter the age of this person : ");
InputAge = stdin.nextInt();
if(InputAge <minAge){
minAge = InputAge;
minName = InputName;
}else if(InputAge>maxAge){
maxAge = InputAge;
maxName = InputName;
}
}
System.out.println("The oldest person is: " + maxName);
System.out.println("The age of the oldest person is: " + maxAge);
System.out.println("The youngest person is: " + minName);
System.out.println("The age of the youngest person is: " + minAge);
}
}
import java.util.*;
public class TestAge {
public static void main(String[] args) {
String InitialName,InputName,maxName = null,minName = null,StopInput;
int InitialAge,InputAge = 0,maxAge,minAge;
Scanner stdin = new Scanner(System.in);
boolean equals;
System.out.println("Please enter the name : ");
InitialName = stdin.next();
maxName=minName=InitialName;
System.out.println("Please enter the age of this person : ");
InitialAge = stdin.nextInt();
maxAge=minAge=InitialAge;
while(true){ //我想主要是在这里可能要改,但我实在想不到更好的方法了,已经尝试很多次了
System.out.println("Please enter the name : ");
InputName = stdin.next();
if(InputName.equalsIgnoreCase("quit")) break;
System.out.println("Please enter the age of this person : ");
InputAge = stdin.nextInt();
if(InputAge <minAge){
minAge = InputAge;
minName = InputName;
}else if(InputAge>maxAge){
maxAge = InputAge;
maxName = InputName;
}
System.out.println("The oldest person is: " + maxName);
System.out.println("The age of the oldest person is: " + maxAge);
System.out.println("The youngest person is: " + minName);
System.out.println("The age of the youngest person is: " + minAge);
}
}
}