In: Computer Science
1) Define and create an array of integers with the values 5, 7, 8, 9 10, 12 using an initializer list. Print the array. 5.
2) Given the Array below, replace the element at position 3 with the value, 99, using an assignment statement. int [] list = {88, 0, 11, 22, 55, 77}; What is the value of list.length?
Here is code in JAVA:
Question 1:
Code:
public class Array {
public static void main(String[] args) {
int[] list = {5, 7, 8, 9, 10, 12}; // array of integers with the
values
//Print the array
for (int i = 0; i < list.length; i++) {
System.out.println(list[i]);
}
}
}
Output:
Question 2:
Code:
public class Array {
public static void main(String[] args) {
int[] list = {88, 0, 11, 22, 55, 77}; // array of integers with the
values
list[3] = 99; // replace the element at position 3 with the value,
99
//Print the array length
System.out.println("Length of array is : " + list.length);
}
}
Output: