173k views
4 votes
In Java, create a file named ArraysForMe with a main method. Inside the main

method, write code that does the following
a. Declares an integer array with 6 cells. Use a constant to hold the length of
the list.
b. In a loop, assign the value of the loop counter + 10 to each element in the
array. For example, element 0 will be assigned 10 and element 5 will be
assigned 15.
c. Write a method
private static void printArray(int[] nums)
which uses a loop to print out the contents of the array. Call it from main.
d. In a loop, change the value of each element to its current value
multiplied by 100
e. Call printArray to print the array
f. Create another array that can contain 6 integers
g. Copy the values of your first array into the second array
h. Print the first array
i. Print the second array
j. Change the element at position 2 in the second array to 1
k. Print the first array
l. Print the second array

1 Answer

3 votes

Final answer:

To create ArraysForMe file in Java, declare an array, assign values, and use a method to print and manipulate the array.

Step-by-step explanation:

To create the ArraysForMe file in Java with a main method, you can follow these steps:

  1. Declare an integer array with 6 cells using a constant to hold the length of the list.
  2. Use a loop to assign the value of the loop counter + 10 to each element in the array.
  3. Create a private static void method called printArray(int[] nums) to print out the contents of the array.
  4. Inside the main method, call the printArray method to print the array.
  5. Use another loop to change the value of each element to its current value multiplied by 100.
  6. Create a second array that can contain 6 integers.
  7. Use a loop to copy the values of the first array into the second array.
  8. Print the first array.
  9. Print the second array.
  10. Change the element at position 2 in the second array to 1.
  11. Print the first array.
  12. Print the second array.

User Suneth Kalhara
by
8.9k points