Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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<=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<=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<=time; x++)
- {
- hour++;
- if(hour>1)
- {
- distance = time * speed;
- System.out.println(time+ " " +distance);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement