Mark Comparison Program in java

In this post, we will learn Mark Comparison Program in java Programming language.

Question:

Joe and her friend got their marks for the IV semester. They were comparing the common scores which they have got.

Write a java program to find the common scores between two arrays and display the position of the matching scores from the first and second array.

If array size is not matching then display “Invalid array size”.

If no elements are matching then display “No matching scores”.

If any of the elements are negative then display “No Negative Elements”.

Input and output format:

The first input corresponds to the size of the first array

The second input set corresponds to the elements of the first array

The third input corresponds to the size of the second array

The fourth input set corresponds to the elements of the second array

Sample Input1:

4

96

55

88

77

4

55

96

44

66

Sample Output1:

(1,2)(2,1)

Sample Input2:

4

43

54

67

23

5

Sample Output2:

Invalid array size

Sample Input3:

4

96

55

88

77

4

53

67

44

66

Sample Output3:

No matching scores

Sample Input4:

4

1

2

3

4

4

34

-1

Sample Output4:

No Negative Elements

CODE:

import java.util.*;
public class Main {
    public static void main (String[] args){
        Scanner sc=new Scanner(System.in);
        int f=sc.nextInt();
        int flag=0;
        int fa[]=new int[20];
        for(int i=1;i<=f;i++)
        {
            fa[i]=sc.nextInt();
            if(fa[i]<0)
            {
                System.out.println("No Negative Elements");
                System.exit(0);
            }
        }
        int s=sc.nextInt();
        int []sa=new int[20];
        if(f!=s){
            System.out.println("Invalid array size");
        }
        else {
            for(int i=1;i<=s;i++){
                sa[i]=sc.nextInt();
                if(sa[i]<0){
                    System.out.println("No Negative Elements");
                    System.exit(0);
                }
                for(int k=1;k<=f;k++){
                    for(int j=1;j<=s;j++){
                        if(fa[k]==sa[j]){
                            flag=1;
                            System.out.println("("+k+","+j+")");
                        }
                    }
                }
            }
            if(flag==0){
                System.out.println("No matching scores");
            }
        }
    }
}
Next:
  1. Print the characters in descending order
  2. Vowels in a fishBowl
  3. Least offers
Sharing Is Caring