Assignment 5 To create a program that uses an array: Creating and Populating an
ID: 3752613 • Letter: A
Question
Assignment 5 To create a program that uses an array: Creating and Populating an Array In this section, you will create a small array step by step to see how arrays are used. The array will hold salaries for four categories of employees 1. create a ava class called DemoArrayY 2. Add the fomwing main() headers and their corresponding opening curly braces: public class DemoArray public static void main(Stringl] args) 3. On a new line, declare and create an array that can ho ld four doub valuesby typing the following: doublet] salary-new double[4]: 4. One by one, assign four values to the four salary array elements by typing the following: salary[0]6.25: salaryl1]6.55: salary[2]-10.25: salary[3116.85: 5. To confirm that the four values have been assigned, display the salaries one by one using the following code: System.out.println "Salaries one by one are:") System.out.println(salary [0]) System.out.println(salary[1]) System.out.println(salary[2]) System.out.printlnisalary[3]): 6. Add the tuo closing curly braces that end the main) method and the DemoArray class. 7. Run the program. Submit your code and the output as a Notepad attachment fileExplanation / Answer
class DemoArray{
public static void main(String srgs[]){
double[] salary=new double[4];
salary[0]=6.25;
salary[1]=6.55;
salary[2]=10.25;
salary[3]=16.85;
System.out.println("Salaries one by one are:");
System.out.println(salary[0]);
System.out.println(salary[1]);
System.out.println(salary[2]);
System.out.println(salary[3]);
}
}
Output:
Salaries one by one are:
6.25
6.55
10.25
16.85