There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
You can also find further discussion and get answers to your questions over in Language Help.
Agree with a comment or answer? Like () to up-vote the contribution!
import java.util.Arrays;
public class Classroom {
public static void main(String[] args){
// question 1)
String[] students = {"Sade", "Alexus", "Sam", "Koma"};
// question 2)
double[] mathScores = new double[4];
// question 3)
mathScores[0] = 94.5;
// question 4)
mathScores[2] = 76.8;
// question 5)
System.out.println("The number of students in the class is " + students.length);
}
}
Hey, what did I do wrong??? I did exactly as the code asked and the code itself didn’t have any errors but the course said I had it wrong and is asking if I did a double which I did! I added the next question steps after to show I know what I’m doing, so yes I have tried it without those code lines and it still didn’t like the way I formatted the double, but I did it exactly as they wanted! am I missing something???
I would like to share my humoristic extension to this exercise,
which uses more values and some string concatenations:
import java.util.Arrays;
public class Classroom {
public static void main(String[] args){
String[] students = {"Sade", "Alexus", "Sam", "Koma"};
double[] mathScores = new double[4];
mathScores[0] = 94.5;
mathScores[2] = 76.8;
System.out.println("The number of students in the class is " + students.length + ".\n");
System.out.println(students[0] + " got a grade of " + mathScores[0] + "% on the test.");
System.out.println(students[2] + " got a grade of only " + mathScores[2] + "% on the same test...");
System.out.println("As for " + students[3] + ", she got a grade of... " + mathScores[3] + "% on the test?!\n");
System.out.println("Oh, that's right: I forgot to set all the values in the mathScores array '-_-");
}
}
So, the actual problem was only in space?
I had the same issue, I continued till the end and the result in terminal was good, but I had the same error message about completing the task.
When I deleted that space, it was ok.
Yes. There should not be a space between double and the opening square bracket. In order for your code to compile properly, you have to follow this syntax:
double[] myArray = new double[5];
In my previous message, I mentioned that the indentation was incorrect. I was wrong. The indentation in the screenshot, while not best practice, does not have any effect on how the code compiles or runs.
I think my issue is the words the lessons use aren’t consistent in the instructions. For example in this lesson they used words like declaring and initializing to describe what actions to take. Then in the instructions they said I need to create. I find myself feeling dumb often because I misunderstand these subtle differences in communication. Am I the only one?
public static void main(String args){
String students = {“Sade”, “Alexus”, “Sam”, “Koma”};
double mathScores = new double[4];
mathScores[0] = 94.5;
mathScores[2] = 76.8;
System.out.println("The number of students in the class is " + students.length + “.”);
}
}
I was told earlier that String is a class (though, for some reason, Codecademy insists that it’s an object). What is surprising for me is that double is a class too, it turns out! Otherwise, how would I be able to create an object with double[] mathScores = new double[4]; (when you use that new operator, you technically create an object, don’t you?)? Are primitives, in fact, classes?
Why do they have me making an array in main and not in a class using a constructor? I wish these lesson would tell me why I’m sometimes putting lines of code in some places and other times in others.