Java Program to Convert Feet Per Second to Miles Per Hour

In the previous article we have discussed about Java Program to Convert Kilometer to Yard and Yard to Kilometer

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

Java Program to Convert Feet Per Second to Miles Per Hour

Feet is used as a unit of length to measure smaller distances while Mile is used as a unit of length to measure long distances.

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

1 Foot Per Second = 0.681818 Miles Per Hour

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

Miles Per Hour = Feet Per Second * 0.681818

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

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

Approach:

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

Program:

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

Output:

1.0 feet per second is equal to 0.681818 miles per hour

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

Approach:

• Take the value of double variable ‘feetPerSecond‘ as user input.
• Then convert feet per second to miles per hour 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 feet per second: ");
//declared double variable feetPerSecond
//and taking it's value as user input
double feetPerSecond=sc.nextDouble();
//converting feet per second to mioes per hour
double milesPerHour=feetPerSecond*0.681818;
//printing result
System.out.println(feetPerSecond+" feet per second is equal to "+milesPerHour+" miles per hour");
}
}

Output:

Enter the value of feet per second: 2
2.0 feet per second is equal to 1.363636 miles per hour

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

Approach:

• Take the value of double variable ‘feetPerSecond‘ as user input.
• Then call a user defined method say convertValue() by passing feetPerSecond value as parameter.
• Then convert feet per second to miles per hour 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 feet per second: ");
//declared double variable feetPerSecond
//and taking it's value as user input
double feetPerSecond=sc.nextDouble();
//calling user defined method converValue()
convertValue(feetPerSecond);
}

//convertValue() user defined method
public static void convertValue(double feetPerSecond)
{
//converting feet per second to miles per hour
double milesPerHour=feetPerSecond*0.681818;
//printing result
System.out.println(feetPerSecond+" feet per second is equal to "+milesPerHour+" miles per hour");
}
}

Output:

Enter the value of feet per second: 3.3
3.3 feet per second is equal to 2.2499994 miles per hour

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: