import java.util.Scanner;
public class DataAnalysis {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
/**System.out.println(!(4<1)|0>4);
System.out.println(4<2|10>4);
int a=12;
System.out.println(a&13);*/
System.out.println("How many entries?");
int g = in.nextInt();//总共进行多少循环看着
String[] gender = new String[g]; //循环次数 System.out.println("Please enter the name of Person 1:"+name);
int[] age = new int[g];//dsadsadsfa
String[] name = new String[g];
int sd=0;
int c=0;//njlk
int rt=0;
do {
sd+=c;
System.out.println("Please enter the name of Person :"+(c+1));
name[c] = in.next();
System.out.println("Please enter the age of Person : "+(c+1));
age[c] = in.nextInt();
System.out.println("Please enter the gender of Person :"+(c+1));//input相关程序由4段
gender [c]= in.next();
for( ; !gender [c].equals("M")&&!gender [c].equals("F"); gender [c]= in.next()) {
System.out.println(" please enter M or F only:");//性别格式记下来,java词典保留下来,分号必须3个
}
if (gender [c].equals("M")) {
rt++;
}
c++;
}while(c<=g-1);
double mn= sd/g ;
System.out.println("The gender ratio is" +((double)rt/g)+ "male and" +((double)(1-rt)/g)+ "female.");
System.out.println("The mean age is"+mn) ;
My questions: dont know how to compare age input among different put??????????????? than 18) and display both the age and name of the child.? how should I coduct the comparison among different ages??
Aucun commentaire:
Enregistrer un commentaire