Java Program to Convert Miles Per Hour to Feet Per Second

In the previous article we have discussed about Java Program to Convert Meters Per Second to Miles Per Hour

In this article we are going to see how to convert miles per hour to feet per second by using Java programming language.

Java Program to Convert Miles Per Hour to Feet Per Second

Both Miles and Feet are used as a unit of length to measurement.

Before jumping into the program, first let’s know the relation between miles per hour and feet per second.

1 Miles Per Hour =1.46667 Feet Per Second

Then the formula to convert miles per hour to feet per second is

Feet Per Second = Miles Per Hour * 1.46667

Let’s see different ways to convert miles per hour to feet per second.

Method-1: Java Program to Convert Miles Per Hour to Feet Per Second By Using Static Input Value

Approach:

  • Declare a double variable say ‘milesPerHour‘ and initialize it’s value.
  • Then convert miles per hour to feet per second by using formula.
  • Print the result.

Program:

public class Main
{
    public static void main(String[] args) 
    {
        //declared value of miles per hour
        double milesPerHour=1;
        //converting miles per hour to feet per second
        double feetPerSecond=milesPerHour*1.46667;
        //printing result
        System.out.println(milesPerHour+" miles per hour is equal to "+feetPerSecond+" feet per second");
    }
}
Output:

1.0 miles per hour is equal to 1.46667 feet per second

Method-2: Java Program to Convert Miles Per Hour to Feet Per Second By Using User Input Value

Approach:

  • Take the value of double variable ‘meterPerSecond‘ as take its’ value user input.
  • Then convert miles per hour to feet per second by using formula.
  • Print the result.

Program:

import java.util.*;
public class Main
{
    public static void main(String[] args) 
    {
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter the value of miles per hour: ");
        //declared double variable milesPerHour
        //and taking it's value as user input
        double milesPerHour=sc.nextDouble();
        //converting miles per hour to feet per second
        double feetPerSecond=milesPerHour*1.46667;
        //printing result
        System.out.println(milesPerHour+" miles per hour is equal to "+feetPerSecond+" feet per second");
    }
}
Output:

Enter the value of miles per hour: 15
15.0 miles per hour is equal to 22.000049999999998 feet per second

Method-3: Java Program to Convert Miles Per Hour to Feet Per Second By Using User Defined Method

Approach:

  • Take the value of double variable ‘milesPerHour‘ as take its’ value user input.
  • Then call a user defined method say convertValue() by passing milesPerHour¬†value as parameter.
  • Then convert miles per hour to feet per second by using formula.
  • Print the result.

Program:

import java.util.*;
public class Main
{
    public static void main(String[] args) 
    {
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter the value of miles per hour: ");
        //declared double variable milesPerHour
        //and taking it's value as user input
        double milesPerHour=sc.nextDouble();
        //calling user defined method converValue()
        convertValue(milesPerHour);
    }
    
    //convertValue() user defined method 
    public static void convertValue(double milesPerHour)
    {
        //converting miles per hour to feet per second
        double feetPerSecond=milesPerHour*1.46667;
        //printing result
        System.out.println(milesPerHour+" miles per hour is equal to "+feetPerSecond+" feet per second");
    }
}
Output:

Enter the value of miles per hour: 20
20.0 miles per hour is equal to 29.333399999999997 feet per second

Have you mastered basic programming topics of java and looking forward to mastering advanced topics in a java programming language? Go with these ultimate Advanced java programs examples with output & achieve your goal in improving java coding skills.

Related Java Programs: