Total members 11894 |It is currently Sat Nov 23, 2024 9:05 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Code:
import java.io.*;
import java.util.*;

public class 
ComparingArrays{
  public static 
void main(String[] argsthrows IOException{
    
int[] array1 = new int[5];
    
int[] array2 = new int[5];
    
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    try{
      
System.out.println("Enter 5 numbers for the first Array : ");
      for(
int i 0array1.lengthi++){
        
array1[i] = Integer.parseInt(in.readLine());
      }
      
System.out.println("Enter 5 numbers for the second Array : ");
      for(
int i 0array2.lengthi++){
        
array2[i] = Integer.parseInt(in.readLine());
      }
    }
    catch(
NumberFormatException ne){
      
ne.printStackTrace();
    }

    
boolean check Arrays.equals(array1array2);
    if(
check == false)
      
System.out.println("Arrays are not same.");
    else
      
System.out.println("Both Arrays are same.");
  }


you can see that the given program initializes two arrays and input five number from user through the keyboard. And then the program checks whether the given taken both arrays are same or not. This comparison operation is performed by using the equals() method of Arrays class



_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Comparing Arrays in java
 Comparing Dates in Java     -  
 Arrays in java     -  
 Multidimensional arrays in Java     -  
 creating arrays in java     -  
 How to compare two arrays in java     -  
 Passing arrays as function parameter in java     -  
 Arrays using Pointers     -  
 Concept of arrays     -  
 Arrays in photoshop     -  
 Defining arrays in ASP     -  



Topic Tags

Java Arrays






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com