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
String word = “Awesome”;
Ilia_Sergeevich [38]
I don’t understand this question
7 0
3 years ago
Read 2 more answers
1. A database table can hold ??
IRINA_888 [86]

Answer:

who are interested and I have been trying to

3 0
3 years ago
Write a function called missing_letters that takes a string parameter and returns a new string with all the letters of the alpha
kompoz [17]

A string parameter and returns new string with all the letters of the alphabet that are not in the argument string. The letters in the returned string should be in alphabetical order. The implementation should uses a histogram from the histogram function

Explanation:

The below code is written in python :

alphabet = "abcdefghijklmnopqrstuvwxyz"

test_dups = ["zzz","dog","bookkeeper","subdermatoglyphic","subdermatoglyphics"]

test_miss = ["zzz","subdermatoglyphic","the quick brown fox jumps over the lazy dog"]

def histogram(s):

   d = dict()

   for c in s:

       if c not in d:

           d[c] = 1

       else:

           d[c] += 1

   return d

def has_duplicates(s):

   for v in histogram(s).values():

       if v > 1:

           return True

   return False

def test_dups_loop():

   for s in test_dups:

       print(s + ':', has_duplicates(s))

def missing_letters(s):

   r = list('abcdefghijklmnopqrstuvwxyz')

   s = s.lower()

   for c in s.lower():

       if c in r:

           r.remove(c)  # the first matching instance

   return ''.join(r)

def test_miss_loop():

   for s in test_miss:

       print(s + ':', missing_letters(s))

def main():

   test_dups_loop()

   test_miss_loop()

if __name__ == '__main__':

   main()

6 0
3 years ago
Explain how loops can be utilized in list processing. Please provide Python examples in your response.
Dominik [7]

Answer:

data = [0,1,2,3,4]

for i in range(4):

   print(data[i])

   i+=1

Explanation:

Loops can be utilized in a listing process by looping back to a list with a variable while the loop increases that variable to give a different response from the list.

8 0
2 years ago
Determining Correct Date Function What function text would you use to put today's date and time in a cell? 0 =TODAYO =NOWO O NOW
Murrr4er [49]

Current date formula:

=TODAY()

Current time formula:

=NOW()

As you can see, the =TODAY() formula only includes the day, month and year. The =NOW() function displays more information, showing the day, month, year, hour and minutes (using a 24-hour clock)

if useful mark as brainliest

3 0
3 years ago
Other questions:
  • How to check what level you are in runescape?
    9·2 answers
  • What to do when the tool bar for paint tool sai dissapears?
    12·1 answer
  • Help me I'm so confused by this question
    7·1 answer
  • analyze the ethical issues in the use of information technology in Multinational company (MNC) and support you answer with one e
    15·1 answer
  • Can I use some Company's name in my Research Project. For example, my research is based on E-commerce security and i wanna use A
    14·1 answer
  • An organization is developing an authentication service for use at the entry and exit ports of country borders. The service will
    10·1 answer
  • Sarah is a detail-oriented programmer. While testing her program, what other skill would she have to apply in order to detect al
    11·1 answer
  • Do you think Mortal Combat is cool?
    10·2 answers
  • How would you delete a slide from your presentation after selecting it?
    14·1 answer
  • What is the benefit of hosting a website on a personali
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!