import java.util.Scanner; public class BouncingBall { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); int bounce = 0, time = 0; double height = 0.0; double velocity = 0; System.out.println("Enter the initial velocity of the ball: "); velocity = keyboard.nextDouble(); do { System.out.print("Time: % Height: 1.1f", time, height); time ++; height += velocity; velocity -= 32; if (height < 0) { height *= -0.5; velocity *= -0.5; bounce++; System.out.println("Bounce!"); } } while (bounce < 5); } }
I need all height values in this program to be rounded to the nearest 0.1. The part after printf is what I wrote down from what my professor said to do. However, the program is not running properly. The program does run properly when I do this instead:
System.out.println("Time: " + time + " Height: " + height); time ++;
However, the Height values don't get rounded to the nearest 0.1. How to I make it so the program rounds the height values to the nearest 0.1 using printf?