3. Create a program that will implement the HighArray Class, declare three objec
ID: 3746235 • Letter: 3
Question
3. Create a program that will implement the HighArray Class, declare three objects name Arrl with an array size of 5, Arr2 with an array size of 5 and Arr3 with an array size of 10. Enter 5 numbers for each object Arr1 and Arr2. After filling the object Arr1 and Arr2, your next task is to fill-in the object Arr3 using the content of the Arr1 and Arr2, keep in mind that you need to fill-in Arr3 in alternate values coming from Arr1 and Arr2. Example Assuming the content of Arr1 (1,2,3,4,5) and Arr2 (9,8,7,6,5) The result of Arr3 is (1,9,2,8,3,7,4,6,5,5)Explanation / Answer
import java.util.Scanner;
import java.util.Arrays;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] Arr1 = new int[5];
int[] Arr2 = new int[5];
int[] Arr3 = new int[10];
System.out.print("Enter 5 numbers: ");
for(int i=0; i<5; i++)
{
Arr1[i] = sc.nextInt();
Arr3[2*i] = Arr1[i];
}
System.out.print("Enter another 5 numbers: ");
for(int i=0; i<5; i++)
{
Arr2[i] = sc.nextInt();
Arr3[2*i+1] = Arr2[i];
}
System.out.println("Arr1 = "+Arrays.toString(Arr1));
System.out.println("Arr2 = "+Arrays.toString(Arr2));
System.out.println("Arr3 = "+Arrays.toString(Arr3));
}
}
/*SAMPLE OUTPUT
Enter 5 numbers: 1 2 3 4 5
Enter another 5 numbers: 9 8 7 6 5
Arr1 = [1, 2, 3, 4, 5]
Arr2 = [9, 8, 7, 6, 5]
Arr3 = [1, 9, 2, 8, 3, 7, 4, 6, 5, 5]
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.