我正在尝试构建一个字符串,并放入循环结果“ att”转换为索引为“ i”的字符串。因此,我可以对字符串进行排序,并输出带有学校编号的出勤率最高的学校。谢谢!
import java.util.Scanner;
public class PengjuShanP1 {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
System.out.print("How many schools do you have in your district: ");
int nos = scnr.nextInt();
int[] nums = new int[nos];
System.out.println();
double ax = 0;
for (int i = 1; i < nos + 1; ++i) {
System.out.println("Enter data for school " + i);
System.out.print(" How many students are enrolled in school : ");
int num = scnr.nextInt();
System.out.print(" Enter the attendance for day 1: ");
int d1 = scnr.nextInt();
System.out.print(" Enter the attendance for day 2: ");
int d2 = scnr.nextInt();
System.out.print(" Enter the attendance for day 3: ");
int d3 = scnr.nextInt();
System.out.print(" Enter the attendance for day 4: ");
int d4 = scnr.nextInt();
System.out.print(" Enter the attendance for day 5: ");
int d5 = scnr.nextInt();
double avg = ((d1 + d2 + d3 + d4 + d5) / 5) * 100;
double att = avg / num;
ax = att + ax;
System.out.println();
System.out.println("Attendance " + att + "% for school " + i);
System.out.println();
}
System.out.print(ax);
}
}
问题尚不清楚,数组索引总是从零开始,而不是for循环中提到的1。如果您希望将att存储在String数组中,请声明String数组并将att存储在string数组中