I don't know where my problem is help please. :D
Here's the problem I was assigned to do: Given 2 lists of student names and grades write a program to write the name and grade for a student in the 1st list. The arrays will be of length 12. If the student's name is not in the array, state "The name is not in the list".
Here is my code:
Code Java:
import java.io.*;
public class StudentsandGrades{
public static void main(String [] args) throws IOException{
String input;
String namein;
int count = 0;
int i;
String [] name = new String [12];
int [] grade = new int [12];
BufferedReader myIn = new BufferedReader(new InputStreamReader(System.in));
for(i = 0; i < 12; i++){
System.out.print("Insert name of student " + (i + 1) + " : ");
name [i] = myIn.readLine();
System.out.print("Insert grade of student " + (i + 1) + " : ");
input = myIn.readLine();
grade [i] = Integer.parseInt(input);
}
System.out.print("Enter the name of the student you would like to search for: ");
namein = myIn.readLine();
for(i = 0; i < 12; i++){
if(namein == name [i]){
count++;
break;
}
}
if(count != 0)
System.out.println("Student: " + name[i] + "Grade: " + grade[i]);
if(count == 0)
System.out.println("The name is not in the list");
}
}
For some reason it always says "The name is not in the list" whether it is there or not.
Can you guys help me out?
Re: I don't know where my problem is help please. :D
See the following page: == or equals()
Re: I don't know where my problem is help please. :D
Thank you so much! It works perfectly now!
I guess as you could probably guess I'm kind of new to this, but thank you very much for your help. I really appreciate it. :D