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
Ill give 100 points to whoever gives me the CORRECT answer. I keep getting syntax errors when I do the "add:" part. Can someone
Olin [163]

Answer:

sorry but there is not enough information to complete this

Explanation:

6 0
3 years ago
Read 2 more answers
Jonas is an experienced security professional who recently accepted a position in an organization that uses Check Point firewall
vichka [17]

Answer:

CCSA

Explanation:

CCSA is "Checkpoint Certified Security Administrator". This certification is best suited for Jonas.

8 0
3 years ago
How does tracking changes relate to sharing a workbook in Excel?
ElenaW [278]

Answer:When you highlight changes as you work, Excel outlines any revisions (such as changes, insertions, and deletions) with a highlighting color. On the Review tab, click Track Changes, and then click Highlight Changes. Select the Track changes while editing. This also shares your workbook check box.

Explanation:

8 0
2 years ago
Software that interprets commands from the keyboard and mouse is also known as the
Anni [7]

Software that interprets commands from the keyboard and mouse is also known as the Operating System, your Operating System controls the basic functionalities of your device including executing commands from your keyboard and mouse.

4 0
3 years ago
PLEASE ANSWER THESE TWOO❤️❤️
alisha [4.7K]
Its
1 - c
2 - d
Thank you
8 0
3 years ago
Other questions:
  • ou work as network administrator for an organization that has a Windows-based network. You want to use multiple security counter
    10·1 answer
  • You can create a database using one of the many templates available or by creating a new ______ database.
    9·1 answer
  • What are personal skills?
    5·1 answer
  • If you were looking for a record in a very large database and you knew the ID number, which of the following would be the most d
    6·1 answer
  • what is the purpose of the Outline view in word 2016? check all that apply. 1. editing the format of size and text. 2.working wi
    11·1 answer
  • Assuming dataFile is an ofstream object associated with a disk file named payroll.dat, which of the following statements would w
    9·1 answer
  • Enthusiasm codehs 7.6.4 Write a function called add_enthusiasm that takes a string and returns that string in all uppercase with
    15·1 answer
  • Including the word OR will make a search less specific.<br> O False<br> O True
    8·2 answers
  • What is the first things u do upon seeing this sheet?​
    14·2 answers
  • Which of the following statements is TRUE of a peer-to-peer network?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!