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
Why are you unable to modify the budget file, when you have the allow full control ntfs permission?
Alinara [238K]

I don't really know the perfect answer to this but I would say because of todays technonlogy


3 0
2 years ago
Cameron wants to impress the owner of the company. He creates a graph that shows the improved productivity at the company over t
Umnica [9.8K]
Point, line, or bar graph is what he would use

6 0
3 years ago
Read 2 more answers
Match the following
kakasveta [241]

Answer:

Eraser tool -removes the unwanted part of the drawing.

Row -horizontal space running from left to right.

Text -Primary component of a multimedia.

Drawing Area -Working are of ms point program.

I hope this helps!! Correct me plz if I'm wrong. If I'm right, could you mark me as brainliest?

8 0
2 years ago
Write a program that prompts for a positive integer and prints the factors of all integers from 1 to that input integer. For exa
xeze [42]
74(Frequency) or 34(frequency)
7 0
3 years ago
Consider the following statements: Statement A: In Duplex transmission, either node can transmit while the other node can receiv
sergij07 [2.7K]

Answer:

<u>d. Statement A is true and Statement B is false</u>

Explanation:

Indeed, when using duplex transmission either node can transmit while the other node can receive data from the network. Also, in half-duplex transmission, both the nodes can transmit as well as receive data.

However, in half-duplex transmission, the nodes <em>cannot </em>transmit and receive data at the same time. Hence, this makes Statement B false, while Statement A is true.

4 0
2 years ago
Other questions:
  • In 1–2 sentences describe how you would insert a row in a spreadsheet.
    6·2 answers
  • Designing the moving parts of a car—including the engine, drivetrain, steering, and brakes—is done by what type of engineer?
    11·2 answers
  • Which is a function of network media?
    14·2 answers
  • What financial behaviors will typically lead to a low credit score?
    14·1 answer
  • When possible, you should avoid using _________ variables in a program?
    11·1 answer
  • Does Windows 7 support secure boot in UEFI? Windows eight? Linux UBUNTU version 14?
    8·1 answer
  • Which sentence(s) below are true?a. IP stands for Internet Protocol.b. In most home networks IP addresses are assigned by the In
    6·1 answer
  • A technician has been asked to upgrade a processor and needs to do some research. The computer is just a couple of years old. Wh
    13·1 answer
  • Which components exist in the contextual tab for tables called Design? Check all that apply.
    15·2 answers
  • A __________ is a thorough examination of each aspect of a network to determine how it may be compromised.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!