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

2. Write Java program that does the following: a) Declare an array alpha of 15 e

ID: 3639614 • Letter: 2

Question

2. Write Java program that does the following:
a) Declare an array alpha of 15 elements ofint type.
b) Output the value of the tenth element of the array alpha.
c) Set the value of the fifth element of the array alpha to 35.
d) Set the value of the ninth element of the array alpha to the sum of the sixth and thirteen elements of the array alpha.
e) Set the value of fourth element of the array to the three times the value of the eighth element, minus 57.
f) Output the alpha so that five elements are printed per line.
4. Suppose a list is an array of six elements of type int. What is stored in list after the following Java code executes?
list[0] = 5;
for (int i = 0; i < 6; i++)
{
list[i] = 2 * i + 5;
if (i % 2 == 0)
list[i] = list[i] - 3;
}
6. What is the output of the following program?
public class Exercice6
{
public static void main(String[] args)
{
int[] alpha = new int[5];
alpha[0] = 5;
for (int count =1; count < 5; count++)
{ alpha[count] = 5 * count + 10;
alpha[count - 1] = alpha[count] - 4;
}
System.out.print("List elements: ");
for (int count = 0; count < 5; count++)
System.out.print(alpha[count] + " ");
System.out.println();
}
}

Explanation / Answer

Answer 4)
list [0] :2
list [1] :7
list [2] :6
list [3] :11
list [4] :10
list [5] :15

Answer 6)
List elements: 11 16 21 26 30

Answer 2)

public static void main(String[] args)

{
int[] alpha = new int[15];
int counter = 0;
int printLineCount = 4;

System.out.println("Print Alpha[10] :" + alpha[10]);
System.out.println("Set Alpha [5] :" + 35);
alpha[5] = 35;


System.out.println("Set Alpha [9] : Alpha[6]+Alpha[13]");
alpha[9] = alpha[6] + alpha[13];

System.out.println("Set Alpha [4] : 3*alpha[8]-57");
alpha[4] = 3 * alpha[8] - 57;

for (int i = 0; i < alpha.length; i++)

{
if ((counter / printLineCount) != 1) {
System.out.print(alpha[i] + " ");
counter++;
} else {
System.out.println(alpha[i] + " ");
counter = 0;
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote