Interview Content
- C Programming Coding Questions
- C Pattern Programming Questions
- C Programming Interview Questions
- Java Programming Coding Questions
- Java Pattern Programming Questions
- Java Programming Interview Questions
- Python Programming Coding Questions
- Python Pattern Programming Questions
- Python Programming Interview Questions
- SQL Interview Questions
Java program to compare two arrays are equal or not in size
Ans:
In this tutorial, you will learn how to write Java program to compare two arrays and check that they are equal in size or not.
Below are the approach which we will be follow to achieve our goal:
- Our approach is to check two given arrays are equal in size or not is first we will find the size of both array.
- And then compare the size. If the size are equal then it will print “size of both arrays are equal” and if the size is not equal then it will print “size of arrays are not equal”.
How our program will behave?
As we have already seen above our logic to check the size of given two arrays is equal or not.
In this program we have already two arrays. After the execution of the program it will print the output as per array size after the calculation.
Java Program to check the size of given two arrays are equal or not?
public class Main {
public static void main(String[] args) {
int sum = 0;
int arr1[]={1,2,3,4,5};
int arr2[]={2,3,1,0,5};
if(arr1.length == arr2.length){
System.out.println("Array is equal");
}else{
System.out.println("Array is not equal");
}
}
}
Output:
Python Program to check the size of given two arrays are equal or not?
arr1=[1,2,3,4,5]
arr2=[1,3,4,5,7]
if len(arr1) == len(arr2):
print("array is equal")
else:
print("array is not equal")
Output:
Also prepare these Java Programs:
- Write a program in Java to print the Fibonacci series using iterative method.
- Palindrome program in Java using Iterative method
- Java program to find largest of three numbers
- Java program to sum the digits of a number using recursion
- Java program to swap two numbers using third variable
- Java Program to check if two strings are anagrams
- Java program to find largest and smallest number in an array
- Java Program to find top two maximum number in array
- Java Program to remove duplicate elements from an array
Latest Uploads on Website
- AVL Tree with explanation
- Radix sort algorithm explanation with example
- Quick Sort Algorithm with explanation
- Bubble sorting algorithm with Bubble sort program in C
- Insertion sort algorithm and program in C
- Selection Sort Algorithm and Program in C
- Linear probing technique explanation with example
- Collision in Hashing and Collision resolution technique
- Hashing in data structure with its types
- Binary search tree operations with Program
- Binary search tree in data structure
- Binary search algorithm in data structure with explanation
- linear search in data structure with Algo and Program