I am trying to write a loop that calculates the distance traveled (distance = speed * time). It should use the loop to calc how far the vehicle traveled for each hour of time. My program asks for hours and then mph but its not calculating time * speed. Here is my code. Thanks!
public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter Hours Traveled\t"); int hoursTraveled = input.nextInt(); System.out.println("Enter MPH\t"); int mph = input.nextInt(); String output = "Hours\t\tDistance\n"; for (int i = mph; i < hoursTraveled; i++) { output += String.format("%s\"\t\t\n", i, distance(mph, i)); } System.out.println(output); } public static double distance(int time, int speed) { double distance = (time * speed); return distance;