113k views
4 votes
Write code to check that HairEyeColor is an array. e) Write code to determine: (i) the total number of respondents in the survey.

1 Answer

6 votes

Answer:

Step-by-step explanation:

The following code is written in Java and first checks to see if the class name starts with the character " [ " which would indicate it is indeed an Array. If it is it prints out that it is an Array and then Prints out the number of respondents/entries that the array has. If it is not an Array it prints out that it is not an array.

if (HairEyeColor.getClass().getName().charAt(0) == '[') {

System.out.println("Yes, it is an Array");

System.out.println("HairEyeColor has " + (HairEyeColor.length+1) + " respondents");

} else {

System.out.println("It is NOT an Array");

}

User Newacct
by
4.8k points