为什么一个个输进去可以输出,一下子全部输进去就会报错?哪里的问题?怎么改?
import java.util.Scanner;
class Plant{
String plant;
String name;
int acot;
public Plant(String plant, String name, int acot) {
this.plant = plant;
this.name = name;
this.acot = acot;
out();
}
public void out() {
System.out.println(name+"用"+acot+"小时种"+plant+"。");
}
}
public class oj1516 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int n1=sc.nextInt();
Plant s[]=new Plant[n];
for(int i=0;i<n;i++){
s[i]=new Plant(sc.next(),sc.next(),sc.nextInt());
}
for(int j=0;j<n-1;j++){
for(int k=j;k<n;k++){
Plant tem;
if(s[j].acot>s[k].acot){
tem=s[j];
s[j]=s[k];
s[k]=tem;
}
}
}
int sum=0;
int t=0;
for(int x=0;x<n;x++){
sum+=s[x].acot;
if(sum<=10){
t++;
}
}
System.out.println(n1+"小时至多可以种"+t+"种植物。");
sc.close();
}
}