Reputation: 37
A sample of the code below
double maxHeight;
maxHeight = (Math.pow(speed * Math.sin(angle), 2) / 2 * gravity);
System.out.printf("Maximum height: %.2f", (maxHeight));
The error i receive:
"The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String, double)"
What is the simplest solution to printing only two decimal places using printf method or are there any other solutions without creating a decimalFormat?
Upvotes: 0
Views: 5444
Reputation: 77177
The problem is that varargs is looking for one or more Object
s, and you provided a primitive variable. The simplest method is probably just to wrap it:
System.out.printf("Maximum height: %.2f", Double.valueOf(maxHeight));
Upvotes: 3