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 69ab6d7

Browse files
author
Jay Morales
committed
Add P1.16
1 parent 02aaae7 commit 69ab6d7

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package progsolutions.ch01.p16;
2+
3+
import static java.lang.System.out;
4+
5+
import javax.swing.JOptionPane;
6+
7+
/**
8+
* P0116.java
9+
*
10+
* @author Jay Morales
11+
*/
12+
class P0116 {
13+
/**
14+
* main.
15+
*
16+
* @param args args
17+
*/
18+
public static void main(String[] args) {
19+
String name = JOptionPane.showInputDialog("What is your name?");
20+
out.println("Hello, " + name + "!");
21+
22+
JOptionPane.showInputDialog("My name is Hal! What would you like me to do?");
23+
out.println("I'm sorry, " + name + ". I'm afraid I can't do that.");
24+
}
25+
}

‎src/progsolutions/ch01/p16/README.md‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[Back](../README.md)
2+
3+
## P1.16
4+
5+
Modify the program from Exercise P1.15 so that the dialog continues with the message "My name is Hal! What would you like me to do?" Discard the user's input and display a message such as
6+
7+
```
8+
I'm sorry, Dave. I'am afraid I can't do that.
9+
```
10+
11+
Replace Dave with the name that was provided by the user.
12+
13+
---
14+
15+
Solution:
16+
17+
```java
18+
import static java.lang.System.out;
19+
20+
import javax.swing.JOptionPane;
21+
22+
class P0116
23+
{
24+
public static void main(String[] args)
25+
{
26+
String name = JOptionPane.showInputDialog("What is your name?");
27+
out.println("Hello, " + name + "!");
28+
29+
JOptionPane.showInputDialog("My name is Hal! What would you like me to do?");
30+
out.println("I'm sorry, " + name + ". I'm afraid I can't do that.");
31+
}
32+
}
33+
```

0 commit comments

Comments
(0)

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