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
how to write java programe and example programe

Public class ConversionProgram {  public void start() {    String userChoice = askConversionCategory();   while (userChoice.equals("1") || userChoice.equals("2") || Page 2

Create a thread in either a C or a Java program and run it. The thread should read a keyboard value "x" and exit from the code, or it can also use an "ESC" to exit. That is, the t


Session Bean : is a non-persistent object that provides some business logic running on the server. Session beans do not provide system break down. There are two kinds of session b

Using Java, write the class Time which consists of the following: (a) three private integer data members (hours, minutes and seconds). (b) a constructor to initialise the dat

1. Create a text file (you can name it sales.txt) that contains in each line the daily sales of a company for a whole month. Then write a Java application that: a. asks the user fo

1. Obtaining the new script: Download and save the attached comment CGI mailer script form-mail2.pl to your server''s cgi-bin directory, and change the permissions on the script to

What is Multiple Inheritance ? A few object oriented languages, notably C++, permits a class to inherit from more than one unrelated class. This is known as multiple inheritanc

Describe life cycle of thread. Threads follow the single flow of control. A thread is execution in a program. The life cycles of threads are listed below: Newborn state: A