Write a program that contains code for each of the following items. Write the co
ID: 3599990 • Letter: W
Question
Write a program that contains code for each of the following items. Write the code in the program and document it according to the numbered item below such as: //part a a. Declare a constant called A SIZE which equals the value 10. Declare an array called scores which contains ten elements of type int and use the constant A SIZE. Declare the variables x and y and set their values to 5 and 10. Initialize the values of the elements of the array to five times the index values. b. Write a displayScoresO which is passed the array scores and A SIZE. Print out the values of the array by using a for-loop.Explanation / Answer
public class ArrayForLoop {
public static void main(String[] args) {
//Answer for a
final int A_SIZE=10;//Final value
int[] scores=new int[A_SIZE];//Declare array with final value
int x=5;
int y=10;
//Intializing the scores with defaulut size
scores[0]=34;
scores[1]=2342;
scores[2]=234;
scores[3]=243;
scores[4]=55;
scores[5]=777;
scores[6]=8854;
scores[7]=35;
scores[8]=78;
scores[9]=313;
int k=A_SIZE*x;
//Answer for b
displayScores(scores);
}
public static void displayScores(int[] scores)
{
for(int i=0;i<scores.length;i++)
{
//System.out.println("Scores are :::"+i);//Here i am displaying the index
System.out.println("Scores are :::"+scores[i]);//Displaying the scores please un comment you can display like this
}
}
}
=================
Scores are :::34
Scores are :::2342
Scores are :::234
Scores are :::243
Scores are :::55
Scores are :::777
Scores are :::8854
Scores are :::35
Scores are :::78
Scores are :::313
=====================
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.