title: Distance Traveled loop help Java
body: <p>I've been racking my brain trying to figure out why my program isn't looping right. Rather than getting each hour increments I'm only getting the final hour/speed. So if I put that I'm going 40 mph for 3 hours I only get 120.              </p>
  
  <p>Here is the problem:</p>
  
  <p>The distance a vehicle travels can be calculated as follows:
  Distance = Speed * Time
  For example, if a train travels 40 miles-per-hour for three hours, the distance traveled is 120 miles. Write a program that asks for the speed of a vehicle (in mph) and the number of hours it has traveled. It should use a loop to display the distance a vehicle has traveled for each hour of a time period specified by the user. For example, if a vehicle is traveling at 40 mph for a three-hour time period, it should display a report similar to the one that follows:
  Hour Distance Traveled</p>
  
  <p>1 40</p>
  
  <p>2 80</p>
  
  <p>3 120</p>
  
  <pre><code>import java.util.Scanner;
  
  public class Distance{
    public static void main(String [] args){
    Scanner keyboard = new Scanner(System.in);
  
    int time , speed ,  hour;
    double  distance;
  
    System.out.println("How fast were you going ?");
    speed = keyboard.nextInt();
  
    while(speed&lt;=0)
    {
       System.out.println("Please enter a valid speed ");
       speed = keyboard.nextInt();
    }
  
    System.out.println(" How long did you ride / drive ?");
    time = keyboard.nextInt();
  
    while(time&lt;=0)
    {
       System.out.println("Please enter a valid time ");
       time = keyboard.nextInt();
    }
  
    System.out.println(" Hour                         Distance");
    System.out.println("---------------------------------");
    hour = 0;
  
  
    for( int x = 1; x&lt;=time; x++)
    {
       hour++;
       if(hour&gt;1)
       {
          distance = time * speed;
          System.out.println(time+ "                " +distance);
       }
      }
     }
    }
  </code></pre>