Ask the user for the size of the cellBills1 array Enter numb

Ask the user for the size of the cellBills1 array: Enter number of elements: Declare an array called cellBills1 of size numElements. Ask the user for the size of the cellBills2 array: Enter number of elements: Declare another array called cellBills2of size numElements. Set a boolean variable isEqual to true. Use a loop to fill values of cellBills1 with user input. Use a second loop to fill values of cellBills2 with user input. Compare the lengths of the arrays. If they are not equal, set isEqual to false. If they have equal lengths, compare each element of cellsBills1 to the corresponding indexed element of cellBills2. If the elements are not equal, set isEqual to false. If the arrays are the same in both length and values, print cellBills1 and cellBills2 are equal. Otherwise, print cellBills1 and cellBills2 are not equal

Solution

import java.util.*;
import java.lang.*;
import java.io.*;


class arrays
{
   public static void main (String[] args)
   {
       Scanner scan = new Scanner(System.in);
       int i;
      
       System.out.println(\"Enter the size of cellBills1 Array\");
       int numElements = scan.nextInt();
      
       int[] cellBills1 = new int[numElements]; //input size of cellBills1
      
       System.out.println(\"Enter the size of cellBills2 Array\");
       numElements = scan.nextInt(); //input size of cellBills2
      
       int[] cellBills2 = new int[numElements];
      
       boolean isEqual = true;
           System.out.println(\"Enter the elements of array cellBills1:\");
       for(i=0;i<cellBills1.length;i++) //input values for array cellBills1
       cellBills1[i] = scan.nextInt();
      
          System.out.println(\"Enter the elements of array cellBills2:\");
       for(i=0;i<cellBills2.length;i++)
       cellBills2[i] = scan.nextInt(); //input values for array cellBills2
      
       if(cellBills1.length != cellBills2.length) //compare size of arrays
       isEqual = false;
       else
       {
           for(i=0;i<numElements;i++)
           {
               if(cellBills1[i] != cellBills2[i]) //compare all elements of arrays
                 
               isEqual = false;
           }
       }
      
       if(isEqual == true)
       System.out.println(\"Arrays cellBills1 and cellBills2 are equal in length and values\");
       else
       System.out.println(\"Arrays cellBills1 and cellBills2 are not equal\");
      
      
      
   }
}

output:

 Ask the user for the size of the cellBills1 array: Enter number of elements: Declare an array called cellBills1 of size numElements. Ask the user for the size
 Ask the user for the size of the cellBills1 array: Enter number of elements: Declare an array called cellBills1 of size numElements. Ask the user for the size

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site