Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m in java one and need help with this code. please follow the directions give

ID: 3686916 • Letter: I

Question

I'm in java one and need help with this code. please follow the directions given and test your program to make sure it works as it is required

Programming Concepts 1. Searching and sorting arrays Assignment Description Write a program that will have the user enter in values for two arrays. Then sort them, and check to see if they're the same. Assignment Suggestions For this assignment only, you may use the Arrays library to sort and print the arrays. To use the library, do: import java.util.Arrays at the top of your program. To sort an array, you can do the following: int[] x-l9, 8, 7,6 . Arrays.sort (x)

Explanation / Answer

SameArray.java


import java.util.Arrays;

public class SameArray {
   public static void main(String arg[]){
       java.util.Scanner in = new java.util.Scanner(System.in);
       System.out.println("Please enter the size of an array ");
       int size = in.nextInt();
       int arr1[] = new int[size];
       int arr2[] = new int[size];
       System.out.println("Please enter in "+size+" integers for array #1 : ");
       for(int i=0; i<arr1.length; i++){
           arr1[i] = in.nextInt();
       }
       System.out.println("Please enter in "+size+" integers for array #2 : ");  
       for(int i=0; i<arr2.length; i++){
           arr2[i] = in.nextInt();
       }
       Arrays.sort(arr1);
       System.out.println("Array 1: "+Arrays.toString(arr1));
       Arrays.sort(arr2);
       System.out.println("Array 2: "+Arrays.toString(arr2));      
      
       boolean status = Arrays.equals(arr1, arr2);
       if(status == true)
           System.out.println("The arrays are the same");
       else
           System.out.println("The arrays are not the same");
   }
}

Output

Please enter the size of an array
5
Please enter in 5 integers for array #1 :
1 2 3 4 5
Please enter in 5 integers for array #2 :
5 4 3 2 1
Array 1: [1, 2, 3, 4, 5]
Array 2: [1, 2, 3, 4, 5]
The arrays are the same

Please enter the size of an array
5
Please enter in 5 integers for array #1 :
1 2 3 4 5
Please enter in 5 integers for array #2 :
9 8 7 6 5
Array 1: [1, 2, 3, 4, 5]
Array 2: [5, 6, 7, 8, 9]
The arrays are not the same

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote