public static void userClass() throws IOException
String data="";
String classroom="";
System.out.println("Please enter the class");
classroom = sc.nextLine().toLowerCase();
String subject=classroom.toUpperCase();
boolean match=false;
BufferedReader input = new BufferedReader(new FileReader("data.txt"));
data = input.readLine();
Scanner scanner = new Scanner(System.in);
data = input.readLine();
int subjectIndex = 10;
String items[]=new String [11]; // rows
while(data!=null)
{
data=input.readLine();
if (data==null)
break;
items=data.split(",");
for (int x=0; x<items.length; x++)
{
if (items.length>10)
{
if (items[10].contains(classroom))
{
match=true;
}
}
}
}
if (match==true)
{
System.out.println("There are " + items[0] + "," + items[1]+ "(" +items[2]+ ")" + " student's enrolling in" +classroom);
}
else if (match==false)
{
System.out.println("The subject " +subject+ " is not taught at our school");
}
all the students who are enrolled in a course specified by the user
This is the question i tried doing both of them however i kept on getting an error saying ArraylangIndexBoundException :10
.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…