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
In programming, what is an object? Object is a named collection of properties (data and state) & methods (instructions, behaviour). Objects are key to understanding object-orie

A framework for building server-side user interfaces for Web applications is written in the Java programming language.

No, java is not fully object oriented language due to it does not support "multiple inheritance" and "pointers" which are used in C++. But, by using Interfaces we can execute multi

These applications are like any Java application. They are made up of not many classes, each performing a particular purpose within the application. But these classes are configure

By pressing ‘6’ (i.e. key’6’ one time) on the keypad, the mobile shows ‘m’ on display screen in write text message area

Explain data entry issues? DATA ENTRY: There is new data entered every day. New customers are added every day. Some of the data entry needs the manual entry within computer s

You are required to write a program that is going to be used to store the student details of a particular school.  This school caters for students aged between 5 years to 15 years.

How to catch multiple exceptions explain with example? If multiple blocks match the exception type, the first block in which matches the kinds of the exception catches it. pub

1. In this lab assignment we will be using the vim or emacs editor in addition to the commands we have already learned. Open a shell terminal and create a file named in your home d

Suppose that: A is the set of characters in the string "pellet"; B is the set of characters in the string "teller"; C is the set of characters in the string "pertinent"; a