How to Compare First and Last Number of Two Arrays

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

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.

1 comments:

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

    ReplyDelete