public static int totalCorrect(String [] studentArray, String [] ansArray){

int numCorrect = 0; 
			
for (int i = 0; i < 6; i++){
				
if (studentArray[i] == ansArray[i])
					
numCorrect += 1;
									
			
}
			
return numCorrect;
			

		
}

instead of returning the actual number, it always return 0.

here is the whole program:

import java.util.Scanner;
public class DriverExam{
	public static void main (String [] args){
		
		
Scanner kb = new Scanner(System.in);
		
String [] answers = {"b","d","a","a","c","a"};
		
String [] studentAs = new String [6];
		
		
for (int i = 0; i < 6; i++){
			
System.out.println("enter student's answer for #" + (i+1));
			
studentAs[i] = kb.nextLine();
		
}
		
		
int correct = totalCorrect(studentAs, answers);
		
System.out.println(correct);
			
}

		
		
public static int totalCorrect(String [] studentArray, String [] ansArray){
			
int numCorrect = 0;
			
			
for (int i = 0; i < 6; i++)
			
{
				
if (studentArray[i] == ansArray[i])
					
numCorrect += 1;
						
			
}
			
return numCorrect;
			
	
}
	
		
		
}

nevermind, i fixed it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.