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
If you mistakenly write pseudocode into an editor for an actual programming language, such as python or visual basic, errors wil
Galina-37 [17]
True.

Pseudo-code (false code) is just for a preliminary "drawing" of the logic needed.
6 0
3 years ago
If you want to convert 10,560 feet to miles in Microsoft Excel, which formula will you see?
AveGali [126]
D it is d kidsssssssssssssssssssssssss
6 0
3 years ago
Read 2 more answers
Consider the following two tables where EmployeeNum is primary key in both tables. What is the result of combining the two table
oee [108]

Answer:

The result of combining the both tables is:

Employee(EmployeeNum, LastName, FirstName, WageRate, SocSecNum, DepartmentNum, Street, City, State, PostalCode)

Explanation:

Since the EmployeeNum is the primary and it is available in both tables, what happens is that, it will not list the primary key column twice. It will list the primary key first then all the other attribute in the first table followed by the attribute in the second table. And it will take note so as not to repeat attribute that already occur in the first table.

For instance; in this case, besides EmployeeNum, LastName and FirstName also appear in the both tables but only one instance of them were listed in the resulting table.

4 0
3 years ago
After earning a learner’s license, what test must be successfully passed to earn an operator’s license?
ZanzabumX [31]
<span>The correct answer is Driving Skills Test.  After earning a learner’s license, Driving Skills test must be successfully passed to earn an operator’s license.  </span>50 hours of driving has to be documented and 10 hours driving at night time.
7 0
3 years ago
Write a letter to your principal to arrange a field trip​
blondinia [14]

Answer:

Dear Mrs/Ms/Mr ( Principal Name ) ,

Since I am a student who only wants the best for the school,my fellow students and myself included,I am politely asking for a field trip.Because I think this would be educational and fun aswell.If you are still not convinced with this letter alone,maybe I can gather up the students' opinions through a petition.I'll be waiting for your response.

Sincerely , ( Student Name ) from ( Class name )

4 0
3 years ago
Other questions:
  • Brenda's working on improving a Google Search Ads quality score so it potentially gets a better ad rank and performs better in t
    9·1 answer
  • Assuming that the actual process ids of the parent and child process are 2600 and 2650 respectively, what will be printed out at
    10·1 answer
  • Create and execute a SELECT statement that would provide data for a vendor directory. Display should include vendor number, vend
    13·1 answer
  • What is a parameter variable?
    8·1 answer
  • Assume that input file references a Scanner object that was used to open a file. Which of the following while loops shows the co
    6·1 answer
  • Loretta is shooting her product separately. She plans to integrate it into the main advertisement later on. What should Loretta
    7·1 answer
  • You work for a company that is growing. Originally, all the users in all departments had access to all the data in the database.
    6·2 answers
  • When you open as many links as you want, and still stay in the same browser window instead of cluttering your screen with multip
    5·1 answer
  • Gauthmath https://s.tutorus.xyz/lp/invite?code=GGQGBL​
    13·1 answer
  • A Python file that contains variables and functions and can be used in other programs is called a
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!