Java program of Mark Comparison

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:-

Main.java

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

Recommended:-

  1. Array square
  2. Generate number using odd digits
  3. Alternate Number Difference
  4. Next Greatest number
  5. Mark Comparison
  6. Print the characters in descending order
  7. Vowels in a fishBowl
  8. Least offer
  9. Ascending and descending order
  10. Mail Domain
  11. Count repeating words
  12. Sentence – Convert to upper and lower
  13. Count consecutive repeating characters
  14. Zig zag Array
  15. Pass and Fail Count
  16. Search a Course
  17. Average and Grade Calculation
  18. String – Find and replace the character (first occurrence)
  19. Sort the first and second half of an array
  20. Retail Shop
  21. Palindrome
  22. Numerology
  23. InitCap
  24. Array Compatiblilty
  25. Sum of the maximum and the minimum element
  26. String Concatenation
  27. Find Average Age
  28. Login
  29.  

Leave a Comment

Your email address will not be published. Required fields are marked *