Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
metzu
5,907 PointsHow to correctly output float value in console?
console is giving me the hash code instead of the float value
public class Main {
public static void main(String[] args) {
GradeBook book = new GradeBook();
book.addGrade(89f);
book.addGrade(77.5f);
book.addGrade(99.5f);
GradeStatistics stats = book.computeStatistics();
writeResult("Average", stats.averageScore, 89.5f);
writeResult("highestScore", stats.highestScore);
writeResult("lowestScore", (int)stats.lowestScore);
}
static void writeResult(String description, float... result) {
System.out.println(description + " :" + result);
}
static void writeResult(String description, int result) {
System.out.println(description + " :" + result);
}
}
```java
Console output is
Average :[F@1540e19d
highestScore :[F@677327b6
lowestScore :[F@14ae5a5
1 Answer
Seth Kroger
56,416 PointsBecause you're using varargs for the float parameters to writeResults to pass multiple ones, result will be an array of floats, not a single float. As a result you'll need to interate through the array to print what you want.
metzu
5,907 Pointsmetzu
5,907 Pointsthanks...