samedi 5 mars 2016

/varible int time won't display the numeric value entered

//varible int time won't display the numeric value entered

The Speed of Sound The following table shows the approximate speed of sound in air, water, and steel: Medium Speed Air 1,100 feet per second Water 4,900 feet per second Steel 16,400 feet per second Write a program that asks the user to enter “air”, “water”, or “steel”, and the distance that a sound wave will travel in the medium. The program should then display the amount of time it will take. You can calculate the amount of time it takes sound to travel in air with the following formula: Time 5 Distance / 1,100 You can calculate the amount of time it takes sound to travel in water with the following formula: Time 5 Distance / 4,900 You can calculate the amount of time it takes sound to travel in steel with the following formula: Time 5 Distance / 16,400

C:\Users\DeLaCruz\Desktop\j2

V:\CSC106-Spring 2016\j3

import java.util.Scanner;

public class ProgramSpeedOfSound{

public static void main(String [] args){

    Scanner keyboard = new Scanner(System.in);

    String input;


    System.out.println("Enter Air, water or steel ");
    input = keyboard.nextLine().toUpperCase();

if(input.equals("Air")){


System.out.println("what is the Distance? ");
int Distance = keyboard.nextInt();
int var = 1100;
double time = Distance / var;

System.out.println("it would take " + time);

}
else if(input.equals("Water")){


System.out.println("what is the Distance? ");
int Distance = keyboard.nextInt();

    double time = (((Distance/ 4900)));

System.out.println("it would take " + time);
}
else{

System.out.println("what is the Distance? ");


    int Distance = keyboard.nextInt();

    double time = Distance/ 16400;

System.out.println("it would take " + time);

    }
   }
 }

Aucun commentaire:

Enregistrer un commentaire