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
Why did latex replace wax?
andrezito [222]

Answer:

Latex replaced wax because it did the same thing and was used for the same things that wax would be used for

Explanation:

3 0
2 years ago
Does anyone know this ? this website is scratch btw.
Katarina [22]

Answer:

maybe select an instrument

7 0
3 years ago
Please I need help with this !!!! <br> Complete the table given below.
UkoKoshka [18]

Answer:

  • DBMS , function - include concurrency, security, backup and recovery, integrity and data descriptions.
  • Software calculator , category - calculator
  • DTP , function - Creating, editing, saving and printing documents.
8 0
3 years ago
Match the different sources of payments to their descriptions. an electronic device that aids consumers to make online payments
LekaFEV [45]

<u>Automatic Draft-</u> A convenient payment method where funds are automatically debited from your account.

<u>Cash-</u> The physical form of currency.

<u>Credit Card-</u> Allows you to make a purchase and pay for it later.

<u>Digital Wallet-</u> An electronic device that aids consumers to make online payments through various websites.

For anyone still looking, hope this helps.

6 0
3 years ago
Are u a chicken nugget!!??
creativ13 [48]
Yes. Yes I would classify myself as the nugget of the chicken thank you for asking me. 
3 0
3 years ago
Read 2 more answers
Other questions:
  • Write an essay on online collaboration, how to do it, the challenges, resolving the challenges, and consider whether the risks a
    12·1 answer
  • If you want to copy text formatting from one area of your document to another area, _____.
    5·2 answers
  • What was the major sign that lead Professor Shiller to predict the crash of the housing market​
    6·1 answer
  • Which system utility can you use to troubleshoot a computer that's slow to start by enabling or disabling startup programs?
    7·2 answers
  • How can volunteering yo help plan fundraiser for your team or club be a way to develop your strengths?
    13·1 answer
  • The larger the Word Size of a computer
    6·1 answer
  • Anyone down to play gta later i play on ps4?
    15·2 answers
  • 1. Which sentence best expresses the main idea
    12·1 answer
  • Three types of query​
    13·1 answer
  • What is the full form of MOS<br>​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!