code, JAVA Programming

pls telme source code for Padovan String
Posted Date: 9/1/2012 2:34:49 AM | Location : United States





package test.padovanstring;

public class PadovanString {
public int stringOccurrences(int n, String str){

if(n >= 40)
return -1;
if(str.replaceAll("X|Y|Z","").length()>0)
return -1;
String res=pad(n);
return(res.length() - res.replaceAll(str,"").length())/(str.length());
}
public String pad(int n){
if(n == 0) return "X";
if(n == 1) return "Y";
if(n == 2) return "Z";
else return pad(n-2) + pad(n-3);

}
public static void main(String []args)
{
PadovanString p = new PadovanString();
System.out.println(p.stringOccurrences(21,"YZ"));
}
}
Posted by gourav | Posted Date: 9/7/2012 11:48:55 AM


Related Discussions:- code, Assignment Help, Ask Question on code, Get Answer, Expert's Help, code Discussions

Write discussion on code
Your posts are moderated
Related Questions
It helps to resolve naming conflicts when different packages have classes with the same names. This also helps you prepare files within your project. As define : java.io package

1-4 Problem Set: Arithmetic Consider the following statement when responding to questions 1 and 2: Jim develops 5 Java applications a year. Joe develops 10 Java applications a year

Notice that each row now has the type of customer and the additional data needed. calculateBill remains the same in Customer.  However, the calculateBill in Corporate will add a

how do you write the code so the line will be clipped

1.   final - it is a constant declaration. 2.   finally - handles exception. The finally block is optional and gives a mechanism to clean up regardless of what occurs within

How does an exception permeate through the code? An unhandled exception moves up the method stack in search of a matching When an exception is thrown from a code which is wrapp

Explain the term array and Scope of Variable? Defining the space in that a variable is effective is known as describing the scope of a variable. A variable can be either local

Develop a GeoNetwork Template Project Description: Want a personalized GeoNetwork Template with the consideration of the logo included to this proposal and its colors. The ba

1. Write the code for the method that calculates the number of unique shapes for a binary search tree with n nodes. Use the formula  where b n is the number of possible sh

(Tic-Tac-Toe)  Create class TicTacToe that will enable you to write a complete application to play the game of Tic-Tac-Toe. The class contains a private 3-by-3 rectangular array o