In the previous article we have discussed about Java Program to Convert Inch to Mile and Mile to Inch
In this article we will see how to convert Inch to Nautical Mile and Nautical Mile to Inch by using Java programming language.
Java Program to Convert Inch to Nautical Mile and Nautical Mile to Inch
Before jumping into the program let’s know the relationship between Inch and Nautical Mile and how we can convert Inch to Nautical Mile and vice versa.
Generally Inch and Nautical Mile are used as unit in case of length measurement.
1 Nautical Mile = 72913.4 Inch 1 Inch = 1.37149e-5 Nautical Mile
Formula to convert Inch to Nautical Mile.
Nautical Mile = Inch / 72913
Formula to convert Nautical Mile to Inch.
Inch = Nautical Mile * 72913.4
Let’s see different ways to convert Inch to Nautical Mile and Nautical Mile to Inch.
Method-1: Java Program to Convert Inch to Nautical Mile and Nautical Mile to Inch By Using Static Input Value
Approach:
- Declare Inch and Nautical Mile value.
- Then convert Inch to Nautical Mile and Nautical Mile to Inch by using the formula.
- Print result.
Program:
import java.util.*; public class Main { public static void main(String args[]) { //Scanner class object created Scanner sc=new Scanner(System.in); //value of nautical mile declared double nauticalMile = 1; // value of inch declared double inch = 1; //converting inch to nautical mile double nm = inch / 72913; //converting nautical mile to inch double in = nauticalMile * 72913.4; //printing result System.out.println("Value of "+nauticalMile+" nautical mile in inch: "+ in); System.out.println("Value of "+inch+" inch in nautical mile: "+ nm); } }
Output: Value of 1.0 nautical mile in inch: 72913.4 Value of 1.0 inch in nautical mile: 1.371497538161919E-5
Method-2: Java Program to Convert Inch to Nautical Mile and Nautical Mile to Inch By Using User Input Value
Approach:
- Take user input of Inch and Nautical Mile value.
- Then convert Inch to Nautical Mile and Nautical Mile to Inch by using the formula.
- Print result.
Program:
import java.util.*; public class Main { public static void main(String args[]) { //Scanner class object created Scanner sc=new Scanner(System.in); //Taking the value input of double variable nauticalMile System.out.println("Enter value of nautical mile: "); double nauticalMile = sc.nextDouble(); //Taking the value input of double variable inch System.out.println("Enter value of inch: "); double inch = sc.nextDouble(); //converting inch to nautical mile double nm = inch / 72913; //converting nautical mile to inch double in = nauticalMile * 72913.4; //printing result System.out.println("Value of "+nauticalMile+" nautical mile in inch: "+ in); System.out.println("Value of "+inch+" inch in nautical mile: "+ nm); } }
Output: Enter value of nautical mile: 4 Enter value of inch: 700000 Value of 4.0 nautical mile in inch: 291653.6 Value of 700000.0 inch in nautical mile: 9.600482767133434
Method-3: Java Program to Convert Inch to Nautical Mile and Nautical Mile to Inch By Using User Defined Method
Approach:
- Take user input of Inch and Nautical Mile value.
- Call a user defined method by passing Inch and Nautical Mile value as parameter.
- Inside method convert Inch to Nautical Mile and Nautical Mile to Inch by using the formula.
- Print result.
Program:
import java.util.*; public class Main { public static void main(String args[]) { //Scanner class object created Scanner sc=new Scanner(System.in); //Taking the value input of double variable nauticalMile System.out.println("Enter value of nautical mile: "); double nauticalMile = sc.nextDouble(); //Taking the value input of double variable inch System.out.println("Enter value of inch: "); double inch = sc.nextDouble(); //calling user defined method convert() convert(nauticalMile, inch); } //convert() method to convert nautical mile to inch and vice versa public static void convert(double nauticalMile, double inch) { //converting inch to nautical mile double nm = inch / 72913; //converting nautical mile to inch double in = nauticalMile * 72913.4; //printing result System.out.println("Value of "+nauticalMile+" nautical mile in inch: "+ in); System.out.println("Value of "+inch+" inch in nautical mile: "+ nm); } }
Output: Enter value of nautical mile: 2.5 Enter value of inch: 2999999 Value of 2.5 nautical mile in inch: 182283.5 Value of 2999999.0 inch in nautical mile: 41.14491242988219
The best and excellent way to learn a java programming language is by practicing Simple Java Program Examples as it includes basic to advanced levels of concepts.
Related Java Programs: