In Java:
Create an array of Integers with 10 elements, loop (use a for loop) through the array of integers printing their values to the screen.
Create an array of Strings with 10 elements, loop (use a for loop) through the array of Strings printing their values to the screen.
Finally, create an ArrayList of Integers. Use the loop from part 1 above and add each integer as you print it to the ArrayList as well, then start a final loop (using the for each nomenclature) to print out the list of Integers.
Below is the complete and running Java code (well commented, indented for your understanding ) containing all the three implementations. Also attached are the sample output and the code screenshots.
import java.util.ArrayList;
class Example
{
public static void main (String[] args) throws java.lang.Exception
{
//declare array of size 10 of type integer
//and initialize the array
int [] array = new int[] {1,2,3,4,5,6,7,8,9,10};
System.out.println("Integer Array");
for(int i = 0; i<array.length ; i++) { //loop through the array
System.out.println("Element at index " + i + " = "+ array[i]);
}
//declare string array of size 10
String[] str_array = new String[] {"This","is","an","example","java","program","for",
"learning","arrays","."};
System.out.println("\nString Array");
for(int i = 0; i<str_array.length ; i++) {
System.out.println("Element at index " + i + " = "+ str_array[i]);
}
ArrayList<Integer> array_list = new ArrayList<Integer>(); //creates an empty array list
for(int i = 0; i<array.length ; i++) {
array_list.add(array[i]); //add element at index i in array to array_list
}
//print the arraylist
for (int i : array_list) {
System.out.println(i);
}
}
}
Output and screenshots:
Integer Array
Element at index 0 = 1
Element at index 1 = 2
Element at index 2 = 3
Element at index 3 = 4
Element at index 4 = 5
Element at index 5 = 6
Element at index 6 = 7
Element at index 7 = 8
Element at index 8 = 9
Element at index 9 = 10
String Array
Element at index 0 = This
Element at index 1 = is
Element at index 2 = an
Element at index 3 = example
Element at index 4 = java
Element at index 5 = program
Element at index 6 = for
Element at index 7 = learning
Element at index 8 = arrays
Element at index 9 = .
1
2
3
4
5
6
7
8
9
10
Screenshots: (to refer indentation)
![JAVA (HotSpot 8u 112) 1 2 3 7 8 9 11 import java.util.ArrayList; class Example 4-{ 5 public static void main (String[] args)](http://img.homeworklib.com/questions/17ecea10-1679-11ec-b795-c3dd798bc59e.png?x-oss-process=image/resize,w_560)
Please do let me know for sure if you have any kind of doubts/questions regarding the solution or anything, I would be happy to help you. Thanks
In Java: Create an array of Integers with 10 elements, loop (use a for loop) through...
In java, request and read in 10 integers from the terminal and put into an ArrayList. Remember, an ArrayList can only store object references, so you will need to take advantage of autoboxing. Then add the numbers together that have been placed in the array, first with the use of an iterator, and then with an enhanced for loop, printing out the results in each case.
Create an array size 10 and fill it with integers from 1 to 10. Print out the values. Then, create a pointer that points to the beginning of the array. Finally, print out all the values through a pointer and the memory address where the value is. With C
Write a Java program that will create an array of Strings with 25 elements. Input Strings from the user and store them in the array until either the user enters “quit” or the array is full. HINT: the sentinel value is “quit” all lowercase. “Quit” or “QUIT” should not stop the loop. HINT: you have to use the equals method (not ==) when you are comparing two Strings. After the input is complete, print the Strings that the user entered...
write a java program
Accept a positive integer n from keyboard and then create an array or arraylist containing n random elements within the range [-n,n). Print out the random array or arraylist, and then find out and print out the number of inversions and the maximum subarray (index range of the maximum subarray along with the maximum subarray sum) in the array or arraylist using divide and conquer, respectively. For example, suppose we accept integer 6 from keyboard, then...
In Java create an integer array named dice1 with a size of 10. Populate each array location with a roll of a six-sided die (hint: an int value of 1 through 6). Print the array out using an enhanced for loop. Sample output: Question 1 dice1 = 1 1 6 2 3 5 1 5 4 5
Write a program that creates an array of 10 integers. The array should be populated with values: each element should be equal to its subscript/index. The program should then print each element. Make use of a loop in storing values to the array. Make use of another loop in printing the values of the array.
in java please Create a command line program Add an array that stores 20 integers Fill the array with random integers between 1 and 1000. Display the values in the array to stdout (the screen). Include a message explaining what is being displayed. Save the values in the array to a text file. Read the values stored in the text file to stdout (the screen). Include a message explaining what is being displayed.
Must use JOPTIONPANE. Using arrays and methods create a JAVA program. Create a java program that holds an array for the integer values 1-10. Pass the array to a method that will calculate the values to the power of 2 of each element in the array. Then return the list of calculated values back to the main method and print the values
Write a program that will create an array of ten integers, allow the user to enter those integers, and eventually search through the array based on index position: 1. Declare the array. You cannot assign elements to an array until it has first been created. 2. Next, run a for loop so that the user can enter an integer to save in each index position of the array. Since you this array holds ten elements , the index position starts...
In Java: Executable Class create an array of Employee objects. You can copy the array you made for Chapter 20. create an ArrayList of Employee objects from that array. use an enhanced for loop to print all employees as shown in the sample output. create a TreeMap that uses Strings for keys and Employees as values. this TreeMap should map Employee ID numbers to their associated Employees. process the ArrayList to add elements to this map. print all employees in...