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
I just finished a small tutorial on JSP and servlet now I was looking for some assignments so that I can try my hands on

#queThis assignment will give you practice with defining classes. You are to write a set of classes that define the behavior of certain animals. You will be given a program that r

Develop Student Portal Project Description: Technology to be used: Java, Portlets, Liferay, functions in Oracle DB, Boostrap. We need develop two pages, a header and foote

I need the five methods public class Ex1Program { public void start() { // Step 1. Declare and construct an array of 19 Movie objects (call the array films)

Conway's Game of Life is a "cellular automaton" that is played on a 2D grid (array) of cells. At the start of the game, an initial configuration is set up in which a number of cell

What is Overloading explain with an example? Overloading is while the similar method or operator can be used on several different kinds of data. For example the + sign is used

Why Local variable is preferred over Global variable ? In my point of view Global variable has a few advantage along with Local variables is preferred because of the subsequent

Enumerate the concept of write once run anywhere - JAVA Java has introduced concept of WORA (write once run anywhere). When you write a java program it is called source code of

Writing a report

What is the difference between Internet and Intranet ? Intranet and internet are 2 domains which are extremely a like but frequent segregated in order to manage security. Inter