嗨,我正在编写一种方法来提示用户输入一些值。我想存储这些值并将一个数组返回给程序。这是我写的代码
public static int[] readInQuarters(String[] firstName, String[] lastName)
{//method to read in quarters
int[] quarter1= new int[firstName.length];
int[] quarter2= new int[firstName.length];
int[] quarter3= new int[firstName.length];
int[] quarter4= new int[firstName.length];
Scanner input=new Scanner(System.in);
for(int i=0;i<firstName.length;i++){
System.out.printf("Enter the 1st quarter figure(to the nearest million) for %s %s :",firstName[i], lastName[i]);
quarter1[i]= input.nextInt();
}
for(int i=0;i<firstName.length;i++){
System.out.printf("Enter the 1st quarter figure(to the nearest million) for %s %s :",firstName[i], lastName[i]);
quarter1[i]= input.nextInt();
}
for(int i=0;i<firstName.length;i++){
System.out.printf("Enter the 2nd quarter figure(to the nearest million) for %s %s :",firstName[i], lastName[i]);
quarter2[i]= input.nextInt();
}
for(int i=0;i<firstName.length;i++){
System.out.printf("Enter the 3rd quarter figure(to the nearest million) for %s %s :",firstName[i], lastName[i]);
quarter3[i]= input.nextInt();
}
for(int i=0;i<firstName.length;i++){
System.out.printf("Enter the 4th quarter figure(to the nearest million) for %s %s :",firstName[i], lastName[i]);
quarter4[i]= input.nextInt();
}
return quarter1;
return quarter2;
return quarter3;
return quarter4;
}
出现 return 季度 1 和其他是无法访问的语句错误。我很困惑为什么?