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;
			
	
}
	
		
		
}

Edited 6 Years Ago by plasticfood: n/a

This question has already been answered. Start a new discussion instead.