// purpose: demonstrate whether some property holds import java.util.*; public class ArrayEqual { public static void main( String[] args ) { // get a scanner for standard input Scanner stdin = new Scanner( System.in ); // determine the desired array size System.out.println(); System.out.print( "Enter the sizes of the two lists: " ); int n1 = stdin.nextInt(); int n2 = stdin.nextInt(); System.out.println(); // create the array int[] a = new int[ n1 ]; int[] b = new int[ n2 ]; // put random binary integers into the elements Random die = new Random(); for ( int i = 0; i < a.length; ++i ) { a[i] = die.nextInt( 2 ); } for ( int i = 0; i < b.length; ++i ) { b[i] = die.nextInt( 2 ); } // display the arrays System.out.print( "a = " ); for ( int i = 0; i < a.length; ++i ) { System.out.print( a[ i ] + " " ); } System.out.println(); System.out.print( "b = " ); for ( int i = 0; i < b.length; ++i ) { System.out.print( b[ i ] + " " ); } System.out.println(); // report whether the two lists have identical elements boolean holds; if ( a.length != b.length ) { // different sizes means there are some differences holds = false; } else { // guess their the same and check for a difference holds = true; for ( int i = 0; i < a.length; ++i ) { } } System.out.println( "Equal: " + holds ); System.out.println(); } }