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

6. Suppose that E is a Java enumeration declared as follows: enum E.) where the

ID: 3602884 • Letter: 6

Question

6. Suppose that E is a Java enumeration declared as follows: enum E.) where the enumeration constants are not shown. Also assume that a is an array of integers whose length is equal to the number of enumeration constants in E. Write a loop that displays each constant in E along with the corresponding element of a. For example, suppose that the enumeration constants are SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, and SATURDAY, in that order, and that the elements of a are 63, 65, 65, 64, 70, 69, and 68. The loop should produce the following output: SUNDAY: 63 MONDAY: 65 TUESDAY 65 WEDNESDAY: 64 THURSDAY: 70 FRIDAY: 69 SATURDAY: 68

Explanation / Answer

public class EnumType {

public enum E {SUNDAY,MONDAY,TUESDAY,WEDNESDAY,THUSDAY,FRIDAY,SATURDAY};

public static void main(String[] args) {

int a[]= {63,65,65,64,70,69,68};

for(int i=0;i<7;i++)

{

System.out.println(E.values()[i]+" : "+a[i]);

}

}

}

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