Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b74062b

Browse files
author
Jay Morales
committed
Add P2.6
1 parent cbce95f commit b74062b

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package progsolutions.ch02.p06;
2+
3+
import static java.lang.System.in;
4+
import static java.lang.System.out;
5+
6+
import java.util.Scanner;
7+
8+
/**
9+
* P0206.java
10+
*
11+
* @author Jay Morales
12+
*/
13+
class P0206 {
14+
private static final Scanner input = new Scanner(in);
15+
private static final double M_PER_MILE = 1609.334;
16+
private static final double M_PER_FOOT = 0.3048;
17+
private static final double M_PER_INCH = 0.0254;
18+
19+
/**
20+
* main.
21+
*
22+
* @param args args
23+
*/
24+
public static void main(String[] args) {
25+
out.print("Enter measurement in meters: ");
26+
final double meter = input.nextDouble();
27+
28+
out.printf("%-8s%20.5f\n", "Miles:", meter / M_PER_MILE);
29+
out.printf("%-8s%20.5f\n", "Feet:", meter / M_PER_FOOT);
30+
out.printf("%-8s%20.5f\n", "Inches:", meter / M_PER_INCH);
31+
}
32+
}

‎src/progsolutions/ch02/p06/README.md‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[Back](../README.md)
2+
3+
## P2.6
4+
5+
Write a program that prompts the user for a measurement in meters and then converts it to miles, feet, and inches.
6+
7+
---
8+
9+
Solution:
10+
11+
```java
12+
import static java.lang.System.in;
13+
import static java.lang.System.out;
14+
15+
import java.util.Scanner;
16+
17+
class P0206
18+
{
19+
private static final Scanner input = new Scanner(in);
20+
private static final double M_PER_MILE = 1609.334;
21+
private static final double M_PER_FOOT = 0.3048;
22+
private static final double M_PER_INCH = 0.0254;
23+
24+
public static void main(String[] args)
25+
{
26+
out.print("Enter measurement in meters: ");
27+
final double meter = input.nextDouble();
28+
29+
out.printf("%-8s%.2f", "Miles:", meter / M_PER_MILE);
30+
out.printf("%-8s%.2f", "Feet:", meter / M_PER_FOOT);
31+
out.printf("%-8s%.2f", "Inches:", meter / M_PER_INCH);
32+
}
33+
}
34+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /