Concept explainers
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...
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
Java: An Introduction to Problem Solving and Programming plus MyProgrammingLab with Pearson eText -- Access Card Package (7th Edition)
- 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
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr