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
o-na [289]
4 years ago
5

(2) Complete the get_num_of_characters() function, which returns the number of characters in the user's string. We encourage you

to use a for loop in this function. (2 pts) Extend the program by calling the get_num_of_characters() function and then output the returned result. (3) Extend the program further by implementing the string_without_whitespace() function. string_without_whitespace() returns the string's characters except for whitespace (spaces, tabs). Note: A tab is '\t'. (2 pt) 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: Theonlythingwehavetofearisfearitself. After you have completed and tested your lab, submit the code of the functions only to Zybook for autograding.
Computers and Technology
1 answer:
dybincka [34]4 years ago
8 0

Answer:

Code details below

Explanation:

// Scanner is a class in the java.util package used to get the entry of primitive types like int, double etc. and also String.

import java.util.Scanner;

// The program must be able to open any text file specified by the user, and analyze the frequency of verbal ticks in the text.  

public class TextAnalyzer {

// public : it is a access specifier that means it will be accessed by publically. static : it is access modifier that means when the java program is load then it will create the space in memory automatically. void : it is a return type i.e it does not return any value. main() : it is a method or a function name.  

 

public static void main(String[] args) {

// the program will find the length of a string without using any loops and you may assume that the length of entered string is always less than any given number

      Scanner scan = new Scanner(System.in);

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

      String s = scan.nextLine();

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

      int numOfCharacters = getNumOfCharacters(s);

      System.out.println("");

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

      outputWithoutWhitespace(s);

  }

  public static int getNumOfCharacters(final String s){

      int numOfCharCount = 0;

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

              numOfCharCount++;

      }

      return numOfCharCount;

  }

   

// Using this function, we replace all whitespace with no space(“”)

  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
A certain computer has a 4meg address space. how many bits wide is this computer's address bus?
PIT_PIT [208]
22 bits






-----------------------------------
4 0
3 years ago
What will you see on the next line?
sammy [17]

Answer:

c [2, 3.5, 7, 9]

Explanation:

8 0
3 years ago
Software that interprets commands from the keyboard and mouse is also known as the ​
Luda [366]

Answer:

THE OPERATING SYSTEM (OS)

Explanation:

6 0
4 years ago
What is a Hyperlink. Give three characteristics of a hyperlink ​
Vitek1552 [10]

Answer:

link destination ("href" pointing to a URL)

link label.

link title.

link target.

link class or link id.

Explanation:

4 0
3 years ago
Read 2 more answers
1. the Magnavox Odyssey was invented by
Tatiana [17]
1. This is tricky. He was an engineer, but not a TV engineer. He was considered the "Father of video games." He was an inventor and game developer as well. I'd probably go with C - Computer Programmer.

2.  A

3. False
5 0
4 years ago
Other questions:
  • 10 facts about turbines
    11·2 answers
  • ____________ is/are the information, knowledge of people or things, and connections that help individuals enter preexisting netw
    13·1 answer
  • Which of the following controls will provide an area in the form for the user to enter a name? a. button b. label c. text box d.
    8·1 answer
  • How do you make someone brainlest
    14·2 answers
  • How do I learn coding? Python
    5·2 answers
  • The third generation of computers was marked by the introduction of ____.
    8·1 answer
  • Write a program to enter a number and test if it is greater than 45.6. If the number entered is greater than 45.6, the program n
    8·1 answer
  • Can anyone help me with a mental ability work plzz
    12·1 answer
  • An informative presentation can be used for conducting a classroom discussion.
    6·1 answer
  • 1. List three tabs that make up the Ribbon
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!