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

(program in java) Array Exercises: Create a class named ArrayExercises that cont

ID: 3763250 • Letter: #

Question

(program in java)

Array Exercises: Create a class named ArrayExercises that contains the following array tasks in the main method:
1. Write some code that asks the user to enter an integer via the keyboard, use that integer to set the length of an array and populate it with random integers from -17 to 19 (inclusive). Print the array back in a nice way (10 numbers per line with commas and such);
2. Below that write some java to reverse the arrays:

char[] a = {’t’, ’o’, ’y’, ’o’, ’t’, ’a’} char[] b = {’r’, ’a’, ’c’, ’e’, ’c’, ’a’, ’r’}
You should do this by creating new arrays to store the reversal. Then write some more java code to prove to me that array b contains a palindrome, while array a does not.
3. (Challenge:) Write a method in your class called reverseArray that is of void return type and it takes as argument a String array (any String array the teacher can think of!) and it reverses the given array in place. That is, it manipulates the given array and modies it (this is because arrays are passed in to methods by reference and not by value

Explanation / Answer

import java.util.*; public class UserInput { public static void main(String[] args) { List list = new ArrayList(); Scanner stdin = new Scanner(System.in); do { System.out.println("Current list is " + list); System.out.println("Add more? (y/n)"); if (stdin.next().startsWith("y")) { System.out.println("Enter : "); list.add(stdin.next()); } else { break; } } while (true); System.out.println("List is " + list); String[] arr = list.toArray(new String[0]); System.out.println("Array is " + Arrays.toString(arr)); } } package userinput; import java.util.Scanner; public class USERINPUT { public static void main(String[] args) { Scanner input = new Scanner(System.in); //allow user input; System.out.println("How many numbers do you want to enter?"); int num = input.nextInt(); int array[] = new int[num]; System.out.println("Enter the " + num + " numbers now."); for (int i = 0 ; i