Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

JAVA Chapter 4 Test Questions and Answers| Latest Update 100% Solved

Rating
-
Sold
-
Pages
15
Grade
A+
Uploaded on
21-03-2025
Written in
2024/2025

JAVA Chapter 4 Test Questions and Answers| Latest Update 100% Solved

Institution
JAVA
Course
JAVA

Content preview

JAVA Chapter 4 Test Questions and Answers|
Latest Update 100% Solved
Assume that name is a variable of type String that has been assigned a value. Write an
expression whose value is a String containing the first character of the value of name. So if the
value of name were "Smith" the expression's value would be "S". ✔️✔️name.substring(0,1)


Assume that name is a variable of type String that has been assigned a value. Write an
expression whose value is a String containing the second character of the value of name. So if
the value of name were "Smith" the expression's value would be "m". ✔️✔️name.substring(1,2)


Write an expression that results in a String consisting of the third through tenth characters of
the String s. ✔️✔️s.substring(2,10)


Assume that word is a variable of type String that has been assigned a value. Write an
expression whose value is a String consisting of the last three characters of the value of word.
So if the value of word were "biggest" the expression's value would be "est".
✔️✔️word.substring(word.length() - 3,word.length())


Given three String variables that have been declared and given values, firstName, middleName,
and lastName, write an expression whose value is the initials of the three names: the first letter
of each, joined together. So if firstName, middleName, and lastName, had the values "John",
"Fitzgerald", and "Kennedy", the expression's value would be JFK". Alternatively, if firstName,
middleName, and lastName, had the values "Franklin", "Delano", and "Roosevelt", the
expression's value would be "FDR". ✔️✔️"" + firstName.charAt(0) + middleName.charAt(0) +
lastName.charAt(0)


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. ✔️✔️firstWord =
sentence.substring(0,sentence.indexOf(' '));


Assume that given, middle and family are three variables of type String that have been assigned
values. Write an expression whose value is a String consisting of the first character of given
followed by a period followed by the first character of middle followed by a period followed by
the first character of family followed by a period: in other words, the initials of the name. So if
the values of these three variables were "John" "Fitzgerald" "Kennedy", then the expression's
value would be "J.F.K.". ✔️✔️given.charAt(0) + "." + middle.charAt(0) + "." + family.charAt(0) + "."


Given a String variable named sentence that has been initialized, write an expression whose
value is the the very last character in the String referred to by sentence.
✔️✔️sentence.charAt(sentence.length() - 1)


Assume that word is a variable of type String that has been assigned a value. Assume
furthermore that this value always contains the letters "dr" followed by at least two other
letters. For example: "undramatic", "dreck", "android", "no-drip".


Assume that there is another variable declared, drWord, also of type String. Write the
statements needed so that the 4-character substring word of the value of word starting with
"dr" is assigned to drWord. So, if the value of word were "George slew the dragon" your code
would assign the value "drag" to drWord. ✔️✔️drWord = word.substring(word.indexOf("dr"),4);


Write a sequence of statements that finds the first comma in the String line, and assigns to the
variable clause the portion of line up to, but not including the comma. You may assume that an
int variable pos, as well as the variables line and clause, have already been declared. ✔️✔️pos =
line.indexOf(',');
clause = line.substring(0,pos);

Written for

Institution
JAVA
Course
JAVA

Document information

Uploaded on
March 21, 2025
Number of pages
15
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

CA$17.20
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF


Also available in package deal

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
Copilot Harvard University
Follow You need to be logged in order to follow users or courses
Sold
23
Member since
1 year
Number of followers
0
Documents
4415
Last sold
3 weeks ago
A+ GRADES

ON THIS PAGE YOU WILL FIND VERIFIED STUDY MATERIALS TO BOOST YOUR CAREERS. (EXAMS, STUDY GUIDES, TEST BANKS, PRACTICE TEST QUESTIONS, TEXT BOOKS & CLASS NOTES FOR ALL COURSES) LETS WORK SMART TO EXCEL, WELCOME!!!

4.9

8 reviews

5
7
4
1
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions