Question: // We can define two arrays (x,y) as equivalent if they are of the same base type, same length, and // contain the same values

// We can define two arrays (x,y) as equivalent if they are of the same base type, same length, and // contain the same values in the same indices. For example: if x and y are integer arrays and // x={10, 20, 15} and y={10, 20, 15}, they are equivalent. However, if y={10, 15, 20), they are not. // This program reads integers into two arrays and prints true if the arrays are equivalent, false if not // The program is done except that the part to compute equivalency is missing. You are to write that part. //---- Equivalent.java import java.util.Scanner; public class Equivalent { public static void main (String args[]) { int[] x=new int[5]; int[] y=new int[5]; int i; System.out.println("Enter 5 pairs of ints and we will tell you if they are equivalent:"); Scanner kbd=new Scanner (System.in); for (i=0; i<5; i++) { x[i]=kbd.nextInt(); y[i]=kbd.nextInt(); } boolean equiv; //---- Write the statements to assign true to equiv if x and y contain same values in same order; false otherwise System.out.print(equiv); } }
Sample console I/O execution sequence
Enter 5 pairs of ints and we will tell you if they are equivalent: 5 5 6 6 7 7 8 8 9 9 true
Write the statements to assign true to equiv if x and y contain same values in same order; false otherwise

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!