Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 2, Problem 8E
Explanation of Solution
Program:
//include required header files
import java.util.*;
//definition of "Test" class
public class Test
{
//definition of main method
public static void main(String[] args)
{
//declare required the variable
int n, n1, n2;
String s,s1,s2, word;
//assign the string for the variable
s = "Hello, my good friend!";
//trim the string
s = s.trim();
//find the index of empty space
n = s.indexOf(" ");
//divide the string using substring
word = s.substring(0, n);
//find the length of the string
n1 = s.length();
//divide the string using substring
s1 = s...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a program which takes a string from the user and replaces all occurrences of ‘b’ with ‘$’.
Write a program to reverse the given string while preserving the position of spaces.
Trace the evaluation of the expressions and give the resulting values. (Make sure to give a value of the appropriate type, such as including a .0 at the end of a double result. If the result is a String, enclose the String in double quotes.)
8 / 5 + 13 % 2 / 3.0
0 / 4 / 2
(12 + (8 * -1) - 3) / 4 * 2
5 * 7 % 4 + “Hi” + 4 - 3
Chapter 2 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Ch. 2.1 - Prob. 1STQCh. 2.1 - Can a Java program have two different variables...Ch. 2.1 - Prob. 3STQCh. 2.1 - Give the declaration for two variables of type...Ch. 2.1 - Write the declaration for two variables called...Ch. 2.1 - What is the normal spelling convention for named...Ch. 2.1 - Prob. 7STQCh. 2.1 - Prob. 8STQCh. 2.1 - Prob. 9STQCh. 2.1 - Prob. 10STQ
Ch. 2.1 - Prob. 11STQCh. 2.1 - In the Programming Tip entitled Type Casting a...Ch. 2.1 - What is the output produced by the following lines...Ch. 2.1 - What is the output produced by the following lines...Ch. 2.1 - Prob. 15STQCh. 2.1 - Prob. 16STQCh. 2.1 - Consider the following statement from the program...Ch. 2.1 - Prob. 18STQCh. 2.2 - Prob. 19STQCh. 2.2 - What output is produced by the following...Ch. 2.2 - What output is produced by the following...Ch. 2.2 - What output is produced by the following...Ch. 2.2 - What output is produced by the following...Ch. 2.2 - What output is produced by the following...Ch. 2.2 - What is the value of the expression sl.equals(s2)...Ch. 2.2 - What is the value of the expression s1.equals (s2)...Ch. 2.3 - Write Java statements that will cause the...Ch. 2.3 - What is the difference between the methods...Ch. 2.3 - Write a complete Java program that reads a line of...Ch. 2.3 - Write a complete Java program that reads one line...Ch. 2.3 - What output is produced by the following...Ch. 2.4 - Prob. 32STQCh. 2.4 - What is the output produced by the following Java...Ch. 2.4 - Although it is kind of silly, state legislatures...Ch. 2.5 - Prob. 35STQCh. 2.5 - Give a Java statement that will display a dialog...Ch. 2.5 - Give a Java statement that, when executed, will...Ch. 2.5 - Prob. 38STQCh. 2.5 - Write a complete Java program that produces a...Ch. 2.5 - Write a complete Java program that behaves as...Ch. 2 - Write a program that demonstrates the approximate...Ch. 2 - Write a program that demonstrates type casting of...Ch. 2 - Write a program that demonstrates the operator %...Ch. 2 - If u = 2, v = 3, w = 5, x = 7, and y = 11, what is...Ch. 2 - What changes to the ChangeMaker program in Listing...Ch. 2 - If the int variable x contains 10, what will the...Ch. 2 - Write some Java statements that use the String...Ch. 2 - Prob. 8ECh. 2 - Prob. 9ECh. 2 - Write a single Java statement that will display...Ch. 2 - What does the Java code Scanner keyboard = new...Ch. 2 - What does the Java code Scanner keyboard = new...Ch. 2 - Prob. 13ECh. 2 - Many sports have constants embedded in their...Ch. 2 - Prob. 15ECh. 2 - Define named constants that you could use in...Ch. 2 - Write a program that reads three whole numbers and...Ch. 2 - Write a program that uses Scanner to read two...Ch. 2 - Write a program that reads the amount of a monthly...Ch. 2 - Write a program that reads a four-digit integer,...Ch. 2 - Prob. 5PCh. 2 - Prob. 6PCh. 2 - Write a program that converts degrees from...Ch. 2 - Write a program that reads a line of text and then...Ch. 2 - Write a program that will read a line of text as...Ch. 2 - Write a program that asks the user to enter a...Ch. 2 - Write a program that determines the change to be...Ch. 2 - Write a program that reads a 4-bit binary number...Ch. 2 - Prob. 7PPCh. 2 - The Harris-Benedict equation estimates the number...Ch. 2 - Repeat any of the previous programming projects...Ch. 2 - Write a program that reads a string for a date in...Ch. 2 - It is important to consider the effect of thermal...
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.Similar questions
- How to compute the first character of a string that is not repeated?arrow_forwardWrite a program to find the location of the first occurrence of a vowel and replace it with ‘X’. Assume that the string will contain at least one vowel.arrow_forwardI need guidance on this, more so what direction do I take to append to a string and make sure it is returning the string value?arrow_forward
- Write a program to print all the unique characters in a String. For instance, if the input string is “abcb”, the output will be the characters ‘a’ and ‘c’ as they are unique. The character ‘b’ repeats twice and so it will not be printed.arrow_forwardCode it How do you find out if the two given strings are anagrams?.arrow_forwardWrite a program that reverse string on the screen like the following picture:use C++arrow_forward
- Write a program that takes a string and swap the first character and the last character of that string.arrow_forwardwrite java program to check if all the characters of the string are the same or not.arrow_forwardWrite a program that reads a text (string) and prints the letter that starts the most number ofwords in that stringarrow_forward
- Which of the following is most likely to be left out at the end of a line? Exactly why is it being taken out of circulation, if not for any good reason?arrow_forwardWrite a program that moves a circle up, down, left, or right using the arrow keys as shown in Figure (b). Check the boundary to prevent the ball from moving out of sight completely.arrow_forwardGiven a string, find the first non-repeating character in it and return it'sindex. If it doesn't exist, return -1.For example:s = "leetcode"return 0.s = "loveleetcode",return 2..arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr