Hello, I made a program and it works great, but I need the height to be rounded to the nearest 0.1
Here is the program:
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.println("Time: " + time + " Height: " + height); time ++; height += velocity; velocity -= 32; if (height < 0) { height *= -0.5; velocity *= -0.5; bounce++; System.out.println("Bounce!"); } } while (bounce < 5); } }
I tried System.out.printf("Time: " + time + " Height: " + height); instead of println, but the output looks all funny. However, all the numbers are rounded properly. How do I make it so the output doesn't get all messed up?