/*
Compare Two Java int Arrays Example
This java example shows how to compare two integer arrays for equality using
Arrays.equals method.
*/
import java.util.Arrays;
public class CompareIntArraysExample {
public static void main(String[] args) {
//create int arrays
int[] intArray1 = new int[]{27,78,1023};
int[] intArray2 = new int[]{27,78,1023};
/*
To compare two int arrays use,
static boolean equals(int array1[], int array2[]) method of Arrays class.
It returns true if both arrays are equal. Arrays are considered as equal
if they contain same elements in same order.
*/
boolean blnResult = Arrays.equals(intArray1,intArray2);
System.out.println("Are two int arrays equal ? : " + blnResult);
/*
Please note that two int array references pointing to null are
considered as equal.
*/
}
}
/*
Output of the program would be
Are two int arrays equal ? : true
*/
Bookmark/Search this post with:
what the answer of this.
This program will ask the user to enter his choice.
If the user enters 1 meaning you are going to add the first number to the second number.
Hint: pls take note that everything you typed in using keyboard is automatically converted to String. Since you can’t add string to another string. You need to convert the first number to integer equivalent e.g.
(1) Add
(2) Subject
(3) Multiply
(4) Divide
(5) Quit
Enter your choice: 2
Enter First number : 5
Enter Second number: 4
The difference is : 1
(6) Add
(7) Subject
(8) Multiply
(9) Divide
(10) Quit
Enter your choice: 1
Enter First number : 3
Enter Second number: 4
The sum is : 7
(1) Add
(2) Subject
(3) Multiply
(4) Divide
(5) Quit
Enter your choice: 3
Enter First number : 3
Enter Second number: 4
The sum is : 12
Enter your choice: 5