We have 2 array,having some element. Comparing both array element at same index, if equal +4 and -1 if not.
Example:
array1=[a b a b], array2=[a a b b]
explanation:
array1[0]==array2[0] //+4
array1[1]!=array2[1] //-1
aarray1[2]==array2[2] //+4
aarray1[3]!=array2[3] //-1
OUTPUT//6**
My code:
import java.util.Scanner;
class Solution
{
public static int scoreExam(String[] correct, String[] student)
{
int count=0;
for (int i=0;i<correct.length ;i++ )
{
for (int j=0;j<student.length ;j++ )
{
if(i==j)
{
if(correct[i]==student[j])
{
count=count+4;
}
else if(correct[i]!=student[j])
{
count=count-1;
}
}
}
}
return (count);
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
String[] array1String,array2String;
String[] array2;
int n=Integer.parseInt(sc.nextLine());
array1String=sc.nextLine().split("//s+");
array2String=sc.nextLine().split("//s+");
array2=new String[array2String.length];
for (int i=0;i<array2String.length ;i++ )
{
if (array2String[i].equals("blank"))
{
array2[i]="";
}
else
{
array2[i]=array2String[i];
}
}
System.out.println(scoreExam(array1String, array2));
}
}