Array Comapare

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main{
    public static void main(String args[]) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int a[] = new int[5];
        int b[] = new int[5];
        try{

            for(int i=0;i<5;i++){
                a[i] = Integer.parseInt(br.readLine());
            }
            for(int i=0;i<5;i++){
                b[i] = Integer.parseInt(br.readLine());
            }
            if(Arrays.equals(a,b)==true) System.out.println("Two arrays are equal");
            else System.out.println("They are different");
        }catch(NumberFormatException e){
            System.out.println(e);
        }
        
    }
}

No comments:

Post a Comment