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 4bb4f58

Browse files
author
Jay Morales
committed
Add P2.2
1 parent afebe1a commit 4bb4f58

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package progsolutions.ch02.p02;
2+
3+
import static java.lang.Math.pow;
4+
import static java.lang.Math.sqrt;
5+
import static java.lang.System.out;
6+
7+
/**
8+
* P0202.java
9+
*
10+
* @author Jay Morales
11+
*/
12+
class P0202 {
13+
/**
14+
* main.
15+
*
16+
* @param args args
17+
*/
18+
public static void main(String[] args) {
19+
final double paperWidthInches = 8.5;
20+
final double paperLengthInches = 11.0;
21+
final double perimeter = (2 * paperWidthInches) + (2 * paperLengthInches);
22+
final double diagonal = sqrt(pow(paperWidthInches, 2) + pow(paperLengthInches, 2));
23+
24+
out.println("The perimeter of a letter-size sheet of paper is " + perimeter + " inches.");
25+
out.println("The length of its diagonal is " + diagonal + " inches.");
26+
}
27+
}

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[Back](../README.md)
2+
3+
## P2.2
4+
5+
Write a program that computers and displays the perimeter of a letter-size (8.5 x 11 inches) sheet of paper and the length of its diagonal.
6+
7+
---
8+
9+
Solution:
10+
11+
```java
12+
import static java.lang.Math.pow;
13+
import static java.lang.Math.sqrt;
14+
import static java.lang.System.out;
15+
16+
class P0202
17+
{
18+
public static void main(String[] args)
19+
{
20+
final double paperWidthInches = 8.5;
21+
final double paperLengthInches = 11.0;
22+
final double perimeter = (2 * paperWidthInches) + (2 * paperLengthInches);
23+
final double diagonal = sqrt(pow(paperWidthInches, 2) + pow(paperLengthInches, 2));
24+
25+
out.println("The perimeter of a letter-size sheet of paper is " + perimeter + " inches.");
26+
out.println("The length of its diagonal is " + diagonal + " inches.");
27+
}
28+
}
29+
```

0 commit comments

Comments
(0)

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