Advertisement
YORDAN2347

IsEqualSides

Feb 16th, 2021
796
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main
  6. {
  7.  
  8.     public static void main(String[] args)
  9.     {
  10.         int n;
  11.         Scanner sc=new Scanner(System.in);
  12.         System.out.print("Enter the number of elements you want to store: ");
  13.  
  14.         n=sc.nextInt();
  15.  
  16.         int[] array = ReadArray(n, sc);
  17.        
  18.         boolean isEqual = IsEqualSides(array);
  19.        
  20.         System.out.println(isEqual);
  21.     }
  22.  
  23.     private static int[] ReadArray(int n, Scanner sc)
  24.     {
  25.         int[] array = new  int[n];
  26.         System.out.println("Enter the elements of the array: ");
  27.         for(int i=0; i<n; i++)
  28.         {
  29.             System.out.println("Enter element " + i);
  30.             array[i]=sc.nextInt();
  31.         }
  32.         return  array;
  33.     }
  34.  
  35.     private static boolean IsEqualSides(int[] array)
  36.     {
  37.         for (int i = 0; i < array.length/2; i++)
  38.         {
  39.             if (array[i] != array[array.length-1-i])
  40.             {
  41.                 return  false;
  42.             }
  43.         }
  44.         return  true;
  45.     }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement