public static int looker(String x, String y) { int num1 = 0; int stringlength = x.length();...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
public static int looker(String x, String y) { int num1 = 0; int stringlength = x.length(); String str1 = y.toLowerCase(); String str2 = x.toLowerCase(); for (int i = 0; i < str1.length(); i++) { if (((i+stringlength)<str1.length())&&(str1.charAt(i)==str2.charAt(0))) { if (str1.substring(i, i+stringlength).equals(str2)) num1++; } } return num1; } a) What does (str1.substring(i, i+stringlength).equals(str2)) test? b) Why does the program create str1 and str2? c) Combine the two if statements in the easiest way possible. Write the simplest combined test, without the word if on the front, without any spaces except where required, and with parentheses around each unique Boolean term. Keep the test components that you use in the same order as they are now and do not rewrite any individual Boolean term that you use. d) If the user calls this method with ("meDo the crime better luck next time").what value will be returned by method looker? public static int looker(String x, String y) { int num1 = 0; int stringlength = x.length(); String str1 = y.toLowerCase(); String str2 = x.toLowerCase(); for (int i = 0; i < str1.length(); i++) { if (((i+stringlength)<str1.length())&&(str1.charAt(i)==str2.charAt(0))) { if (str1.substring(i, i+stringlength).equals(str2)) num1++; } } return num1; } a) What does (str1.substring(i, i+stringlength).equals(str2)) test? b) Why does the program create str1 and str2? c) Combine the two if statements in the easiest way possible. Write the simplest combined test, without the word if on the front, without any spaces except where required, and with parentheses around each unique Boolean term. Keep the test components that you use in the same order as they are now and do not rewrite any individual Boolean term that you use. d) If the user calls this method with ("meDo the crime better luck next time").what value will be returned by method looker?
Expert Answer:
Answer rating: 100% (QA)
a str1substringi istringlengthequalsstr2 tests whether a substring of str1 starting from index i wit... View the full answer
Related Book For
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp
Posted Date:
Students also viewed these programming questions
-
If f: X Y and g: Y Z are increasing functions, so is their composition g f: X Z. Moreover, if f and g are both strictly increasing, then so is g f.
-
If f: X Y and g: Y Z are continuous function, so is their composition g o f: X Z.
-
If f: X Y and g: Y Z are linear functions, then so is their composition g f: X Z.
-
Define variable. Also discuss variable initialization.
-
Acme Landfill Company is considering the purchase of 10 better trash collection trucks. Each truck costs $50,000 and will last 7 years. The firm estimates that the purchase will increase its annual...
-
Fit a linear trend equation to these data showing the value of shipments of food products in billions of dollars. What is the trend estimate for 2012? Year: 2001 2002 2003 2004 Shipments: $451.4...
-
Are there any cases you can find where a supplemental pleading was allowed because new facts have been alleged? What were the new facts?
-
51. Lance H. and Wanda B. Dean are married and live at 431 Yucca Drive, Santa Fe, NM 87501. Lance works for the convention bureau of the local Chamber of Commerce, and Wanda is employed part-time as...
-
Write two-goal statements based on the scenario Rid heart attacks from the world's population, including breathing-related problems Improve and support policies and procedures that foster healthy...
-
Many institutions have fixed future liabilities to meet (such as pension payments) and they fund these future liabilities using default-free fixed income securities. When discount bonds of all...
-
In the New Keynesian Phillips Curve, if anticiptated future inflation decreases, A. output falls and inflation falls. B. output rises and inflation falls. C. output stays the same and inflation...
-
Discount Rate Required rate of return = 10% Expected Net Cash Flow Year Franchise L Franchise S 0 -100 -100 1 10 65 2 60 50 3 80 20 a) Calculate NPV = $18.78 IRR= MIRR 18.126% 16.50% Decision if...
-
On September 1 , 2 0 2 3 , Betamax S . p . A . sold 1 0 0 units of merchandise for 6 0 , 0 0 0 in exchange for a 1 year, 6 % note receivable. On November 1 of the same year, Betamax discounted its...
-
2) An opening bridge takes 60 seconds to open. The opening motion is shown on the angular velocity time diagram (Figure 14). Figure 14 Angular Velocity (rad.s) 0.03 0.02 0.01 0 10 20 30 40 40 50 60...
-
1. Write a program using MIPS assembly instructions, LI, SW to store array A[10] of 10 integers in a Data Segment. You can use Fibonacci program as a template. You can use first 10 Fibonacci numbers...
-
Translate the following code segment into MARIE's assembly language: Submit: cin >> x; cin >> Y; cout < < x; cout < < Y; Z = X + Y; cout < < Z; x = 0; Y = 0; cout < < x; cout < < Y; Copy of source...
-
When should you choose a product layout over a process layout? When should you choose a process layout over a product layout? ...and how do workers/staff respond to process layouts and product...
-
Is that Yelp review real or fake? The article A Framework for Fake Review Detection in Online Consumer Electronics Retailers (Information Processing and Management 2019: 12341244) tested five...
-
Approximate the runtime of the following code fragment, in terms of n: int sum 0; %3D for (int j 1; j < n; j++) { %3D sum++; if (j % 2 0) { sum++;
-
Draw the min-heap being represented by the given array: [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] 29 41 30 55 68 37 41 80
-
Write a method called surroundWith that takes an integer x and an integer y as parameters and surrounds all nodes in the list containing the value x with new nodes containing the value y. In...
-
True or False. The element stiffness matrices are always singular.
-
Derive the stiffness matrix of the bar element in longitudinal vibration whose cross-sectional area varies as \(A(x)=A_{0} e^{-(x / l)}\), where \(A_{0}\) is the area at the root (see Fig. 12.14)....
-
Fill in the Blank. In the finite element method, the elements are assumed to be interconnected at certain points known as ____________ .
Study smarter with the SolutionInn App