(1) Prompt the user to enter a string of their choosing. Output the string.
Ex: Enter a sentence or phrase: The only thing we have to fear is fear itself. You entered: The only thing we have to fear is fear itself.
(2) Complete the GetNumOfCharacters() function, which returns the number of characters in the user's string. Use a for loop in this function for practice. (2 pts)
(3) In main(), call the GetNumOfCharacters() function and then output the returned result. (1 pt) (4) Implement the OutputWithoutWhitespace() function. OutputWithoutWhitespace() outputs the string's characters except for whitespace (spaces, tabs). Note: A tab is '\t'. Call the OutputWithoutWhitespace() function in main(). (2 pts)
Ex: Enter a sentence or phrase: The only thing we have to fear is fear itself. You entered: The only thing we have to fear is fear itself. Number of characters: 46 String with no whitespace: The only thing we have to fear is fear itself.

Answers

Answer 1

Answer:

See solution below

See comments for explanations

Explanation:

import java.util.*;

class Main {

 public static void main(String[] args) {

   //PrompT the User to enter a String

   System.out.println("Enter a sentence or phrase: ");

   //Receiving the string entered with the Scanner Object

   Scanner input = new Scanner (System.in);

   String string_input = input.nextLine();

   //Print out string entered by user

   System.out.println("You entered: "+string_input);

   //Call the first method (GetNumOfCharacters)

   System.out.println("Number of characters: "+ GetNumOfCharacters(string_input));

   //Call the second method (OutputWithoutWhitespace)

   System.out.println("String with no whitespace: "+OutputWithoutWhitespace(string_input));

   }

 //Create the method GetNumOfCharacters

   public static int GetNumOfCharacters (String word) {

   //Variable to hold number of characters

   int noOfCharactersCount = 0;

   //Use a for loop to iterate the entire string

   for(int i = 0; i< word.length(); i++){

     //Increase th number of characters each time

     noOfCharactersCount++;

   }

   return noOfCharactersCount;

 }

 //Creating the OutputWithoutWhitespace() method

 //This method will remove all tabs and spaces from the original string

 public static String OutputWithoutWhitespace(String word){

   //Use the replaceAll all method of strings to replace all whitespaces

   String stringWithoutWhiteSpace = word.replaceAll(" ","");

   return stringWithoutWhiteSpace;

 }

}


Related Questions

Other Questions
m= 4/5 - 2/5 - = ? -1 - -2 Which number has the same absolute valueas 8 The table shows transactions from five different bank accounts. Fill in the missing numbers How was Giotto's ability to show depth different from more traditional methods? What happened to the immigrants that failed the health exam in order to come into America? Group of answer choices They were treated by doctors and given medicine on the spot They refused to treat them, but gave them a job They went to the hospital right away They were detained and held for further questioning, possibly sent back to Europe What adaptations allow conifers to live in dryhabitats? What is the HELIOCENTRIC model of the solar system? Steven sells bags of different kinds of cookies. He made $27 selling bags of Oreos, $18 selling chocolate chips cookies, and $45 selling chunky sugar cookies. Each bag of cookies costs the same amount. What is the most that Steven could charge for each bag of cookies? Help with these math questions grade 12 A cylindrical water tank is being filled with a hose. The depth of the water increases by 114 ft per hour.How many hours will it take for the water level in the tank to be 312 ft deep?Enter your answer as a mixed number in simplest form Which is an example of a current research focus in chemistry?A. applying gene therapy to treat certain diseasesB. using hook-and-loop tape in the clothing industryC. developing smoke detectors for common useD. studying coal combustion as an energy source Read the following instructions for an imaginary assignment:Confucius is an ancient Chinese philosopher. For this project, create a multi-media presentation that teaches Confucius main philosophical ideas to an audience of your classmates.What is your task in this assignment?to create a multi-media presentationto entertain classmates like yourselfto pretend to be a Chinese philosopherto explain Confucius philosophy 16B+3.5W = 22 Antoine bikes part of the way on a 22 mile trail and walks the rest of the way. If he spends B hours biking and W hours walking, the trip is modeled by the equation shown above. What is the meaning of the 16B in the equation? what happened as a result of over hunting whales These are some events in the suns life. What is the correct sequence of events?A - the sun has a core as hot as a white dwarfB - hydrogen and helium erupt in nuclear fusion to make a new starC - the sun is a giant red ball that swallows some of the inner planetsD - the sun lives billions of years as an average star what is the answer for 3x6+(1) Argue why vertical integration is necessary for Jim in the following scenario.Situation: Jim Smith owns a small ranch and independently sells his corn crop to food producers. His best client did not renew his contract and went with a different farmer because the other farmer offered a lower price than Jim did. what shoukd the patient expect to experience living with the disease- Sitius Inversus?? in ur own words Only do first 4 questions I will give brainlist how do I write a summary of the movie our shining lights