Итак, у меня есть этот метод printStats, чей параметр pList имеет тип данных ArrayList of Passenger:
public static void printStats(ArrayList<Passenger> pList) {
Scanner file = new Scanner( new File( "titanic.csv" ) );
DecimalFormat percent = new DecimalFormat("#.0%");
String header = file.nextLine();
while (file.hasNextLine()){
String gender;
String survived;
int count = 0;
int males = 0;
int females = 0;
int survivedMales = 0;
int survivedFemales = 0;
for(int i=0; i<pList.length;i++) {
if (gender.equals ("M"))
{ males++;
if (survived.equals("yes"))
survivedMales ++;}
else
{
females++;
}
if (survived.equals("yes"))
survivedFemales ++;}
count++
System.out.println("Total number of passengers: " + count);
System.out.println("Total number of male passengers: " + males);
System.out.println("Total number of female passengers: " + females);
System.out.println("Total number of male passengers survived: " + survivedMales);
System.out.println("Total number of female passengers survived: " + survivedFemales);
System.out.println("Survival rate of male passengers: " + percent.format(survivedMales/males));
System.out.println("Survival rate of female passengers: " + percent.format(survivedFemales/females));
}
Я продолжаю получать синтаксис неправильно в for для l oop, в частности в "i
for(int i=0; i<pList.length;i++)
Любая помощь будет принята с благодарностью.