Total members 10261 | Gratitudes |It is currently Tue May 22, 2012 4:45 pm Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Code Snippet
 Code subject: Comparing Arrays in java
PostPosted: Tue Nov 11, 2008 10:42 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time

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

public class ComparingArrays{
  public static void main(String[] args) throws 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 = 0; i < array1.length; i++){
        array1[i] = Integer.parseInt(in.readLine());
      }
      System.out.println("Enter 5 numbers for the second Array : ");
      for(int i = 0; i < array2.length; i++){
        array2[i] = Integer.parseInt(in.readLine());
      }
    }
    catch(NumberFormatException ne){
      ne.printStackTrace();
    }

    boolean check = Arrays.equals(array1, array2);
    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 clas

:grin: :grin: :grin: :grin:

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 Defining arrays in ASP
 video chat application in java
 navigating to database using java
 java mobile apps
 need help in java
 Read your gmail using Java code
 Java Programing to communicating port parallel
 Java Chat
 Steganography in java
 java code for listing folder contents from remote folder

All times are UTC [ DST ]


Users browsing similar codes

Users browsing this forum: Google Adsense [Bot] and 2 guests



Jump to:  
Previous Code Snippet | Next Code Snippet 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team