Assume that sentence is a variable of type String that has been assigned a value. Assume furthermore that this value is a String consisting of words separated by single space characters with a period at the end. For example: "This is a possible value of sentence." Assume that there is another variable declared, firstWord, also of type String. Write the statements needed so that the first word of the value of sentence is assigned to firstword. So, if the value of sentence were "Broccoli is delicious.", your code would assign the value "Broccoli" to firstWord.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter7: User-defined Simple Data Types, Namespaces, And The String Type
Section: Chapter Questions
Problem 3PE
icon
Related questions
Question

java

Assume that sentence is a variable of type String that has been assigned a value.
Assume furthermore that this value is a String consisting of words separated by single space
characters with a period at the end.
For example: "This is a possible value of sentence."
Assume that there is another variable declared, firstWord, also of type String.
Write the statements needed so that the first word of the value of sentence is assigned to
firstWord.
So, if the value of sentence were "Broccoli is delicious.", your code would assign the value
"Broccoli" to firstWord.
1
secondWord =
sentence.split(" ")[1];
2 attempts remaining
36 characters I 5000 maximum
Transcribed Image Text:Assume that sentence is a variable of type String that has been assigned a value. Assume furthermore that this value is a String consisting of words separated by single space characters with a period at the end. For example: "This is a possible value of sentence." Assume that there is another variable declared, firstWord, also of type String. Write the statements needed so that the first word of the value of sentence is assigned to firstWord. So, if the value of sentence were "Broccoli is delicious.", your code would assign the value "Broccoli" to firstWord. 1 secondWord = sentence.split(" ")[1]; 2 attempts remaining 36 characters I 5000 maximum
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Introduction to computer system
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning