Saturday 19 July 2014

How to Compare First and Last Number of Two Arrays

1. Conditional Arrays Matching
2. Check the Length Should Be > 0

Structure of the Problem Requirements 

In this Problem we Compare the Two Arrays with a Specific Condition that if their First or Last Numbers are Same on the Same Indexing then it Should Return True Else Return False. It could be Solve with Boolean Value Like 0,1 But for Better Understanding we solve it with Simple System.out Command. This Program also check the Length of the Array which Should be Greater then Zero in this Condition.

Source Code   

import java.util.Scanner;
public class ArraysProblem {
public static void main(String[] args) {
  Scanner input = new Scanner (System.in);
  int num[]  = new int [5];
  int num2[] = new int [5];
  int count=0;
   System.out.println("Enter  1st Array Integer");
         for (int i= 0; i < 5;i++ )
         {num[i]=input.nextInt();
           }
         System.out.println("Enter 2nd Array Integer");
         for (int k=0;k<5;k++)
         { num2[k]= input.nextInt ();
         }
     for (int m =0; m < 5; m++)
 {if ((num[0] ==num2[0]) || (num[4]==num2[4]))
 {count++;
 }
 }
 if (count > 0)
 {
   System.out.println("True");
 }
 }

}


Output of the Program

Java Array Programming
Compares the Number






Share it Please
asad

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.

1 comments: Post Yours! Read Comment Policy!▼
Important Note:
We have Zero Tolerance to Spam. Chessy Comments and Comments with Links will be deleted immediately upon our review.

  1. Please commenting bhe kr diya kry ta ky easily smjh a sky

    ReplyDelete