1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
marishachu [46]
3 years ago
11

(1) Prompt the user to enter a string of their choosing. Output the string.

Computers and Technology
1 answer:
barxatty [35]3 years ago
6 0

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;

 }

}

You might be interested in
The purpose of the trusted platform module is:
Elza [17]
A Trusted Platform Module is a specialized chip on an endpoint device that stores RSA encryption keys specific to the host system for hardware authentication. Each TPM chip contains an RSA key pair called the Endorsement Key. The pair is maintained inside the chip and cannot be accessed by software.
6 0
2 years ago
Read 2 more answers
Which of the following is true about operating system.
zalisa [80]

Answer:

google kis kam ka hai us se puch lo

7 0
2 years ago
What does nat stand for? network access trigger network administration timetable network address translation network association
Mars2501 [29]
Perhaps I think its NETWORK ADDRESS  TRANSLATIONS
take care:) 
6 0
2 years ago
A newspaper publishes a negative editorial on how local politicians are dragging their feet in building a new bridge. Select the
jeka57 [31]
Your answer would be
A. The editorial is data.
I just took this test :)
6 0
3 years ago
Read 2 more answers
An aggregate function is _____. A. a function that calculates a statistic such as a subtotal or average B. a mathematical expres
Murrr4er [49]

Answer:

  • A. a function that calculates a statistic such as a subtotal or average.

6 0
2 years ago
Other questions:
  • Which sentence best describes an activity stream?
    10·2 answers
  • Assuming arrayName is the name of an array and identifier is a name of a variable that has the same data type as the array eleme
    6·1 answer
  • To use files in a c++ program you must include the ________ header file.
    15·1 answer
  • When is e-mail an appropriate channel for goodwill messages? If you frequently communicate with the receiver by e-mail and are c
    15·1 answer
  • What is the acronym that helps you remember the order of math operations?
    9·2 answers
  • Give one example of a civil engineering structure.
    5·1 answer
  • What is one way to recognize whether an online source has been copyrighted? The source features the phrase “all rights reserved.
    6·2 answers
  • the computer that communicate with each other are called ______please ask the answer in 15 minutes after 1 p.m. ​
    9·1 answer
  • Input two numbers and print their sum products difference division and remainder​
    9·1 answer
  • Can anyone figure this out???? I need help ASAP!
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!