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
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
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images