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
DiKsa [7]
3 years ago
9

Write a function `has_more_zs` to determine which of two strings contains # more instances of the letter "z". It should take as

parameters two string # variables, and return the argument which has more occurances of the letter "z" # If neither phrase contains the letter "z", it should return: # "Neither string contains the letter z." # If the phrases contain the same number of "z"s, it should return: # "The strings have the same number of Zs." # The function must work for both capital and lowercase "z"s.
Computers and Technology
1 answer:
nekit [7.7K]3 years ago
5 0

Answer:

// Method's name: has_more_zs

// Parameters are text1 and text2 to hold the two phrases to be tested

public static String has_more_zs(String text1, String text2) {

 // Create and initialize z1 to zero

 // Use z1 to count the number of zs in text1

 int z1 = 0;

 // Create and initialize z2 to zero

 // Use z2 to count the number of zs in text2

 int z2 = 0;

 

 //Create a loop to cycle through the characters in text1

 //Increment z1 by one if the current character is a 'z'

 int i = 0;

 while (i < text1.length()) {

  if (text1.charAt(i) == 'z' || text1.charAt(i) == 'Z') {

   z1 += 1;

  }

  i++;

 }

 //Create a loop to cycle through the characters in text2

 //Increment z2 by one if the current character is a 'z'

 

 i = 0; //Re-initialize i to zero

 

 while (i < text2.length()) {

  if (text2.charAt(i) == 'z' || text2.charAt(i) == 'Z') {

   z2 += 1;

  }

  i++;

 }

 

 

 //Using the values of z1 and z2, return the necessary statements

 if (z1 > z2) {

  return "The phrase '" + text1 + "'" + " has more occurences of z than the phrase " + "'" + text2 + "'";

 }

 else if (z1 < z1) {

  return "The phrase '" + text2 + "'" + " has more occurences of z than the phrase " + "'" + text1 + "'";

 }

 else if (z1 == z2) {

  return "The strings have the same number of z";

 }

 else {

  return "Neither string contains the the letter z";

 }

}

Explanation:

Explanation to answer has been given in the code as comments. Please refer to the comments for the details of the code.

The source code file has been attached to this response and saved as "NumberOfZs.java"

Hope this helps!

Download java
You might be interested in
Jamal wants to create a program that will play music during the afternoon. Which kind of loop should be used in the program?
AnnZ [28]

Answer:

Nintendo Co., Ltd. is a Japanese multinational consumer electronics and video game company headquartered in Kyoto. The company was founded in 1889 as Nintendo Karuta by craftsman Fusajiro Yamauchi and originally produced handmade hanafuda playing cards

Explanation:

8 0
3 years ago
Read 2 more answers
Is Brainly cheating??
Vanyuwa [196]

Answer: What do you mean?

6 0
3 years ago
Read 2 more answers
Why do computers need to periodically check the dns for websites you have already visited? enter your answer here?
den301095 [7]

The reason why computers has the need to periodically check for the DNS of websites that an individual has already visited because certain websites can change its IP address and that the individual using it can be directed to a different website that he or she does not know of.

6 0
3 years ago
Search engines enable you to
docker41 [41]
The answer is easily <span>locate Web pages related to a specific subject.</span>
6 0
3 years ago
Read 2 more answers
How can presentation software be used in a
atroni [7]

Answer:

to compose letters and memos

to create charts and graphs from a table of

values

to deliver a sales presentation to clients

Explanation:

I forget what the reasoning behind them but I know this is the answer

7 0
3 years ago
Read 2 more answers
Other questions:
  • Ascending and descending are examples of
    5·2 answers
  • Zara is designing a slide with a numbered label on a picture. She wants the number to appear when the she presses a button on th
    11·2 answers
  • I don’t know technically
    9·2 answers
  • The ________ of the operating system enables users to communicate with the computer system. modem window network adapter card us
    14·1 answer
  • an object or device outside the computer, that one would plug into a port to control the functions of a computer are?
    9·2 answers
  • What do you do to add a line or circle to your presentation?
    7·2 answers
  • Cynthia realized that she used a wrong term throughout her paper. Which option can help her quickly correct her mistake?
    5·1 answer
  • This morning when Paul turned on his computer at work, it would not boot. Instead, Paul reported that he heard a loud clicking n
    15·1 answer
  • Additional metadata data is stored alongside the binary colour values for each pixel. Give two examples of metadata?
    9·1 answer
  • A _____ standard describes the requirements for obtaining a domain name for use by external parties?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!