I got the idea from my reference book, that is Java a beginner's guide.
Enter the echo time in seconds then you will get the answer(Enter as an argument. Because i still didn't learn how to get inputs whiteout using arguments ).
Code: Select all
/*
This program finds the distance of one palce to another using echo time of sound.
Gets values as an argument. Enter the value in seconds.
*/
class SoDisCal{
public static void main(String args[]){
try{
double time=Double.parseDouble(args[0]); //Gets the argument
if(time==0){
System.out.println("There is no distance then or you can't count the time");
}
else{
time=time/2; //Divide by 2 to get the distance of a one direction.
time=time*1100; //Converts to feet
System.out.println("Distance to the Object is " +time+" feet away!!!");
}
}
catch(NumberFormatException e){
System.out.println("Fool! enter the amount(That means seconds) in number format ");
}
}
}