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 02aaae7

Browse files
author
Jay Morales
committed
Add P1.15
1 parent b03ccec commit 02aaae7

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package progsolutions.ch01.p15;
2+
3+
import static java.lang.System.out;
4+
5+
import javax.swing.JOptionPane;
6+
7+
/**
8+
* P0115.java
9+
*
10+
* @author Jay Morales
11+
*/
12+
class P0115 {
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+
}

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[Back](../README.md)
2+
3+
## P1.15
4+
5+
Type in and run the following program:
6+
7+
```java
8+
import javax.swing.JOptionPane;
9+
10+
public class DialogViewer
11+
{
12+
public static void main(String[] args)
13+
{
14+
String name = JOptionPane.showInputDialog("What is your name?");
15+
System.out.println(name);
16+
}
17+
}
18+
```
19+
20+
Then modify the program to print "Hello, *name*!", displaying the name that the user typed in.
21+
22+
---
23+
24+
Solution:
25+
26+
```java
27+
import static java.lang.System.out;
28+
29+
import javax.swing.JOptionPane;
30+
31+
class P0115
32+
{
33+
public static void main(String[] args)
34+
{
35+
String name = JOptionPane.showInputDialog("What is your name?");
36+
out.println("Hello, " + name + "!");
37+
}
38+
}
39+
```

0 commit comments

Comments
(0)

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