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
Zarrin [17]
3 years ago
15

Complete the getNumOfCharacters() method, which returns the number of characters in the user's string. We encourage you to use a

for loop in this function. (3) In main(), call the getNumOfCharacters() method and then output the returned result. (1 pt) (4) Implement the outputWithoutWhitespace() method, which outputs the string's characters except for whitespace (spaces, tabs). Note: A tab is '\t'. Call the outputWithoutWhitespace() method in main().
Computers and Technology
1 answer:
photoshop1234 [79]3 years ago
5 0

Answer:

The Java code is given below with appropriate comments

Explanation:

//Program

//Import the necessary libraries

import java.util.Scanner;

//Define the class

public class CountStringCharacters

{

//Start the main method

public static void main(String[] args)

{

//Prompt the user to enter the input line

Scanner scan = new Scanner(System.in);

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

String s = scan.nextLine();

 

//Take the number of characters and keep the count

int numOfCharacters = getNumOfCharacters(s);

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

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

 

//Call the method outputWithoutWhitespace

outputWithoutWhitespace(s);

}

//The method getNumOfCharacters

public static int getNumOfCharacters(String s)

{

int numOfCharCount = 0;

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

{

numOfCharCount++;

}

return numOfCharCount;

}

//Definition of the method outputWithoutspace

public static void outputWithoutWhitespace(String s)

{

String str = "";

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

{

char ch = s.charAt(i);

if(ch != ' ' && ch != '\t')

str = str + ch;

}

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

}

}

You might be interested in
Is a bottle opener considered an engineered item?
KIM [24]
Yes actually it is it’s a machine to use for opening bottles such as cans n other
3 0
3 years ago
Levi wants to run 5 commands sequentially, but does not want to create a shell script. He knows that each command is going to ta
sergeinik [125]

Answer:

um

Explanation:

what subject is this again?

3 0
2 years ago
Fryshta is using the Help window in PowerPoint to learn about inserting Smart Shapes into a presentation. She currently has a He
Rainbow [258]

Answer: Pin

Explanation:

Pin button is the button that is used for sticking or saving the ideas from the windows or web on that very place.This feature helps in reviewing or getting the idea back later anytime from the window as per users need. User use this button for saving any food recipe, steps of any process, guidelines etc.

  • According to the question, Fryshta can use pin button from the help window for sticking or pinning the steps of inserting shapes in her presentation.She can have a look at the steps whenever she want.
8 0
3 years ago
Which of the following statements best describes how digital photographs can be used?
kipiarov [429]

Answer:

umm wheres the options so we can answer it and ty

Explanation:

3 0
3 years ago
Read 2 more answers
What to do if you forgot your locked notes password
rodikova [14]

Answer:

I don't have a Apple, but I suggest you either contact Apple Help, or go to settings and see if you can reset it.

Add-on:

I hope this helped you at all.

5 0
2 years ago
Read 2 more answers
Other questions:
  • Number Analysis Program: Write a program that reads data from the text file numbers.txt. Assume the file contains a series of nu
    14·1 answer
  • ​A(n) ________ database makes it possible to store information across millions of machines in hundreds of data centers around th
    14·1 answer
  • Which tab provide text formatting features
    11·1 answer
  • 21. What is the set of events that occurs between the moment you turn
    7·1 answer
  • The trigonometry book says: sin^2(t) + cos^2(t) = 1 Write a Python program that verifies the formula with the help of the Python
    11·1 answer
  • Two boxes overlap if their interiors have at least one point in common. Give an O(n log n)-time algorithm that decides if there
    8·1 answer
  • Explain what middleware is. Name a common middleware in two-tier client/server architecture for database applications.
    10·1 answer
  • Write a Python3 program to check if 3 user entered points on the coordinate plane creates a triangle or not. Your program needs
    12·1 answer
  • In Python which is the correct method to load a module math?
    10·1 answer
  • Finish the format string to get the output shown below.<br> Day<br> &gt;&gt;&gt;{ v8'_format('Day)
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!