Advertisement
jbozhich

Untitled

Feb 24th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Distance{
  4.   public static void main(String [] args){
  5.   Scanner keyboard = new Scanner(System.in);
  6.  
  7.   int time , speed ,  hour;
  8.   double  distance;
  9.  
  10.   System.out.println("How fast were you going ?");
  11.   speed = keyboard.nextInt();
  12.  
  13.   while(speed<=0)
  14.   {
  15.      System.out.println("Please enter a valid speed ");
  16.      speed = keyboard.nextInt();
  17.   }
  18.  
  19.   System.out.println(" How long did you ride / drive ?");
  20.   time = keyboard.nextInt();
  21.  
  22.   while(time<=0)
  23.   {
  24.      System.out.println("Please enter a valid time ");
  25.      time = keyboard.nextInt();
  26.   }
  27.  
  28.   System.out.println(" Hour                         Distance");
  29.   System.out.println("---------------------------------");
  30.   hour = 0;
  31.  
  32.  
  33.   for( int x = 1; x<=time; x++)
  34.   {
  35.      hour++;
  36.      if(hour>1)
  37.      {
  38.         distance = time * speed;
  39.         System.out.println(time+ "                " +distance);
  40.      }
  41.     }
  42.    }
  43.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement