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 0dd19f6

Browse files
author
Jay Morales
committed
Add P2.12
1 parent 2efae06 commit 0dd19f6

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package progsolutions.ch02.p12;
2+
3+
import static java.lang.System.in;
4+
import static java.lang.System.out;
5+
6+
import java.util.Scanner;
7+
8+
/**
9+
* P0212.java
10+
*
11+
* @author Jay Morales
12+
*/
13+
class P0212 {
14+
/**
15+
* main.
16+
*
17+
* @param args args
18+
*/
19+
public static void main(String[] args) {
20+
final Scanner input = new Scanner(in);
21+
22+
out.print("Enter the drive letter: ");
23+
final String drive = input.next();
24+
System.out.print("Enter the path: ");
25+
final String path = input.next();
26+
out.print("Please enter the filename: ");
27+
final String filename = input.next();
28+
out.print("Please enter the extension: ");
29+
final String extension = input.next();
30+
31+
out.println(drive + ":\\" + path + "\\" + filename + "." + extension);
32+
}
33+
}

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[Back](../README.md)
2+
3+
## P2.12
4+
5+
_File names and extensions._ Write a program that prompts the user for the drive letter `C`, the path `\Windows\System`, the file name `Readme`, and the extension `txt`. Then print the complete file name `C:\Windows\System\Readme.txt`. (If you use UNIX or a Macintosh, skip the drive name and use / instead of \ to separate directories.)
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 P0212
18+
{
19+
public static void main(String[] args)
20+
{
21+
final Scanner input = new Scanner(in);
22+
23+
out.print("Enter the drive letter: ");
24+
final String drive = input.next();
25+
System.out.print("Enter the path: ");
26+
final String path = input.next();
27+
out.print("Please enter the filename: ");
28+
final String filename = input.next();
29+
out.print("Please enter the extension: ");
30+
final String extension = input.next();
31+
32+
out.println(drive + ":\\" + path + "\\" + filename + "." + extension);
33+
}
34+
}
35+
```

0 commit comments

Comments
(0)

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