/** * A Java program to input strings and call methods strings. * * Note: Codecheck will use different input values to test * the program, and you must use the specified variables in * your program. 7 8 * * Step 2: Enter your name for @author and today's date for @version * @author * @version */ 10 11 12 13 14 public class StringProg 15 16 public static void main(String [] args) 17 18 // Step 3: Create a new Scanner object 19 20 21 // Step 4: Display a prompt "Enter multiple words separated by single spaces: 22 23 24 // Step 5: Read in one line of input and store it in a variable line 25 26 27 // Step 6: Display line on one line within double quotes 28 // with message "The original line: " 29 30 31 // Step 7: Trime spaces from both ends of line and save it back to line 32 33 34 // Step 8: Display line on one line within double quotes 35 // with message "The line with spaces trimmed from both ends: 36 37 38 // Step 9: Ask for a word with prompt "Enter a single word: " 39 40 41 // Step 10: Read in a single string and store it in variable word 42 43 44 // Step 11: Display word on one line within double quotes Restricted Mode
/** * A Java program to input strings and call methods strings. * * Note: Codecheck will use different input values to test * the program, and you must use the specified variables in * your program. 7 8 * * Step 2: Enter your name for @author and today's date for @version * @author * @version */ 10 11 12 13 14 public class StringProg 15 16 public static void main(String [] args) 17 18 // Step 3: Create a new Scanner object 19 20 21 // Step 4: Display a prompt "Enter multiple words separated by single spaces: 22 23 24 // Step 5: Read in one line of input and store it in a variable line 25 26 27 // Step 6: Display line on one line within double quotes 28 // with message "The original line: " 29 30 31 // Step 7: Trime spaces from both ends of line and save it back to line 32 33 34 // Step 8: Display line on one line within double quotes 35 // with message "The line with spaces trimmed from both ends: 36 37 38 // Step 9: Ask for a word with prompt "Enter a single word: " 39 40 41 // Step 10: Read in a single string and store it in variable word 42 43 44 // Step 11: Display word on one line within double quotes Restricted Mode
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
![2
3
/**
4
* A Java program to input strings and call methods strings.
* Note: Codecheck will use different input values to test
* the program, and you must use the specified variables in
* your program.
7
8
*
* Step 2: Enter your name for @author and today's date for @version
* @author
* @version
*/
10
11
12
13
public class StringProg
{
public static void main(String [) args)
14
15
16
17
18
1 // Step 3: Create a new Scanner object
19
20
21
// Step 4: Display a prompt "Enter multiple words separated by single spaces: "
22
23
24
// Step 5: Read in one line of input and store it in a variable line
25
26
// Step 6: Display line on one line within double quotes
with message "The original line: "
27
28
//
29
30
31
// Step 7: Trime spaces from both ends of line and save it back to line
32
33
34
// Step 8: Display line on one line within double quotes
35
//
with message "The line with spaces trimmed from both ends: "
36
37
38
// Step 9: Ask for a word with prompt "Enter a single word: "
39
40
41
// Step 10: Read in a single string and store it in variable word
42
43
44
// Step 11: Display word on one line within double quotes
O 0 AO
O Restricted Mode
МacВook Air
esc
80
F1
F2
F3
F4
F5
F6](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F170cb9b5-2292-4ecc-9f24-3c60291ff66d%2F016a23ff-dd08-4913-a0db-4d1ee1737a51%2Fwleoc5b_processed.jpeg&w=3840&q=75)
Transcribed Image Text:2
3
/**
4
* A Java program to input strings and call methods strings.
* Note: Codecheck will use different input values to test
* the program, and you must use the specified variables in
* your program.
7
8
*
* Step 2: Enter your name for @author and today's date for @version
* @author
* @version
*/
10
11
12
13
public class StringProg
{
public static void main(String [) args)
14
15
16
17
18
1 // Step 3: Create a new Scanner object
19
20
21
// Step 4: Display a prompt "Enter multiple words separated by single spaces: "
22
23
24
// Step 5: Read in one line of input and store it in a variable line
25
26
// Step 6: Display line on one line within double quotes
with message "The original line: "
27
28
//
29
30
31
// Step 7: Trime spaces from both ends of line and save it back to line
32
33
34
// Step 8: Display line on one line within double quotes
35
//
with message "The line with spaces trimmed from both ends: "
36
37
38
// Step 9: Ask for a word with prompt "Enter a single word: "
39
40
41
// Step 10: Read in a single string and store it in variable word
42
43
44
// Step 11: Display word on one line within double quotes
O 0 AO
O Restricted Mode
МacВook Air
esc
80
F1
F2
F3
F4
F5
F6
![// Step 12: Trime spaces from both ends of word and save it back to word
// Step 13: Display word on one line within double quotes
//
with message "The word with spaces trimmed from both ends: "
// Step 14: Find out if line contains word and assign
the result to a variable true0rFalse
//
// Step 15: Display the value of trueOrFalse on one line
with message "The line contains the word: "
//
// Step 16: Find out the index of word within line and assign
the result to an integer variable pos
//
// Step 17: Display the value of pos on one line
//
with message "The index of word in line: "
// Step 18: Find out the index of the first space
within line and assign it to pos
//
// Step 19: Display the first word of line on one line
within double quotes with message
//
//
"First word of line: "
// Step 20: Find out the index of the second space within
line and assign it to another int variable
//
// Step 21: Display the second word of line
within double quotes with message
//
//
"Second word of line: "](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F170cb9b5-2292-4ecc-9f24-3c60291ff66d%2F016a23ff-dd08-4913-a0db-4d1ee1737a51%2Fju465te_processed.jpeg&w=3840&q=75)
Transcribed Image Text:// Step 12: Trime spaces from both ends of word and save it back to word
// Step 13: Display word on one line within double quotes
//
with message "The word with spaces trimmed from both ends: "
// Step 14: Find out if line contains word and assign
the result to a variable true0rFalse
//
// Step 15: Display the value of trueOrFalse on one line
with message "The line contains the word: "
//
// Step 16: Find out the index of word within line and assign
the result to an integer variable pos
//
// Step 17: Display the value of pos on one line
//
with message "The index of word in line: "
// Step 18: Find out the index of the first space
within line and assign it to pos
//
// Step 19: Display the first word of line on one line
within double quotes with message
//
//
"First word of line: "
// Step 20: Find out the index of the second space within
line and assign it to another int variable
//
// Step 21: Display the second word of line
within double quotes with message
//
//
"Second word of line: "
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education