Change code in java program so that input of floating point


Change code in Java program so that input of floating point values is possible.

/* Java program which outputs the average speed of an
*object given the distance and time travelled
* (speed = distance/time). */

// Java extension packages
import java.util.*; // import class
import java.io.*; // import class

public class AverageSpeed
{
// main method begins execution of Java application
public static void main( String args[])
{

Scanner input = new Scanner( System.in );

int Distance; // Number keyed in by user representing distance travelled
int Time; // Number keyed in by user representing time taken
int Speed; // Calculated average speed

// Takes input of number to be process representing distance travelled
System.out.print( "Please enter the distance travelled in kilometres: ");
Distance = input.nextInt();

// Takes input of number to be process representing travel time
System.out.print( "Please enter the time taken to cover the distance in hours : ");
Time = input.nextInt();

Speed = Distance/Time; // Calculates the average speed

// display the results calculated average speed
System.out.printf( "Your average speed per hour is: %dn" , Speed );

} // end method main
} // end class AverageSpeed

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Change code in java program so that input of floating point
Reference No:- TGS01251283

Now Priced at $20 (50% Discount)

Recommended (91%)

Rated (4.3/5)