Problem solving using recursion   First code i solve it this is the second part  // define a scanner attached to keyboard available to all functions final static Scanner cin = new Scanner(System.in); /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here out.print("CPS 151 ICA 04 String matching by YOUR NAME\n\n"); out.print("Enter the text (one word): "); String hayStack = cin.next(); out.print("Enter the pattern (one word): "); String needle = cin.next(); if (find(needle, hayStack)) out.println(needle + " was found in " + hayStack); else out.println(needle + " was not found in " + hayStack); } // end main private static boolean find(String needle, String hayStack) { int patLen = needle.length(); int textLen = hayStack.length(); // base case 1 if (patLen > textLen) { // failure } else if (needle.startsWith(needle)) { // base case 2 MODIFY!! // SUCCESS } else { // recurse } return false; // dummy to keep NetBeans happy } // end method

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Problem solving using recursion

 

First code i solve it this is the second part

 // define a scanner attached to keyboard available to all functions final static Scanner cin = new Scanner(System.in); /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here out.print("CPS 151 ICA 04 String matching by YOUR NAME\n\n"); out.print("Enter the text (one word): "); String hayStack = cin.next(); out.print("Enter the pattern (one word): "); String needle = cin.next(); if (find(needle, hayStack)) out.println(needle + " was found in " + hayStack); else out.println(needle + " was not found in " + hayStack); } // end main private static boolean find(String needle, String hayStack) { int patLen = needle.length(); int textLen = hayStack.length(); // base case 1 if (patLen > textLen) { // failure } else if (needle.startsWith(needle)) { // base case 2 MODIFY!! // SUCCESS } else { // recurse } return false; // dummy to keep NetBeans happy } // end method

String matching
Here also I used a loop to try out several matching problems in one run
DD
Output - ICA04_String Match_Key (run) - Editor
Output - ICA04_StringMatch_Key (run) X
run:
CPS 151 ICA 04 String matching by KEY
Enter the text (one word) or QUIT: abaracadabra
Enter the pattern (one word): dabra
dabra was found in abaracadabra
Enter the text (one word) or QUIT: abracadabra
Enter the pattern (one word): racad
racad was found in abracadabra
Enter the text (one word) or QUIT: abracadabra
Enter the pattern (one word): cadaver
cadaver was not found in abracadabra
Enter the text (one word) or QUIT: abracadabra
Enter the pattern (one word): abracadabra
abracadabra was found in abracadabra
Enter the text (one word) or QUIT: QUIT
BUILD SUCCESSFUL (total time: 1 minute 25 seconds)
n
X
<
Transcribed Image Text:String matching Here also I used a loop to try out several matching problems in one run DD Output - ICA04_String Match_Key (run) - Editor Output - ICA04_StringMatch_Key (run) X run: CPS 151 ICA 04 String matching by KEY Enter the text (one word) or QUIT: abaracadabra Enter the pattern (one word): dabra dabra was found in abaracadabra Enter the text (one word) or QUIT: abracadabra Enter the pattern (one word): racad racad was found in abracadabra Enter the text (one word) or QUIT: abracadabra Enter the pattern (one word): cadaver cadaver was not found in abracadabra Enter the text (one word) or QUIT: abracadabra Enter the pattern (one word): abracadabra abracadabra was found in abracadabra Enter the text (one word) or QUIT: QUIT BUILD SUCCESSFUL (total time: 1 minute 25 seconds) n X <
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Can u show all the output?

Solution
Bartleby Expert
SEE SOLUTION
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY