n-th padovan string p(n), JAVA Programming

write a program that count the number of occurences of string in the n-th padovan string p(n)

 

program in java

// aakash , suraj , prem sasi kumar kamaraj college
program 1 :

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"));
    }
}

 

 

 

Program set 2 :

import java.util.Scanner;

import java.util.ArrayList;

 

public class PadovanSeries

{

    public static void main(String[] arg)

    {

        Scanner read = new Scanner(System.in);

        System.out.println("Enter starting no. : ");

        int start = read.nextInt();

        System.out.println("Enter ending no. : ");

        int end = read.nextInt();

        int[] ans = getSeries(start, end);

        System.out.println("Padovan series : ");

        for (int a : ans)

            System.out.print(a + " ");

    }

 

    public static int[] getSeries(int s, int e)

    {

        ArrayList list = new ArrayList();

        int i, j = 0;

        for (i = s; i <= e; i++, j++)

            list.add(getPadovan(i));

        int[] ans = new int[j];

        for (i = 0; i < j; i++)

            ans[i] = list.get(i);

        return ans;

    }

 

    public static int getPadovan(int p)

    {

        if (p == 0 || p == 1 || p == 2)

            return 1;

        return (getPadovan(p - 2) + getPadovan(p - 3));

    }

}

 

Padova

Posted Date: 9/3/2012 1:18:56 AM | Location : United States







Related Discussions:- n-th padovan string p(n), Assignment Help, Ask Question on n-th padovan string p(n), Get Answer, Expert's Help, n-th padovan string p(n) Discussions

Write discussion on n-th padovan string p(n)
Your posts are moderated
Related Questions
What is JDBC exactly? Describe the steps required to execute a SQL query using JDBC.

Need Android GeoLocation Service App Project Description: I want an android service app that will run on the background. The app has to get the users location (latitude an

Modify both of the above clients (to write separate clients) to extract the exchange rate from a live web service that performs currency conversion. You can choose a Java or a .NET

Project Description: We prepare and operate smartphone application.(Picture sharing and social networking) But there are problems in server side. It's very slow. So we

#question.Write a program that computes the edit distance (also called the Levenshtein distance, for its creator Vladimir Levenshtein) between two words. The edit distance between

Explain function arguments with the help of an example? Arguments on a function are comma separated list of data enclosed within braces. It describes interface among the web pa

Write code in JavaScript language to show the odd numbers among 20 to 100 using FOR statement. Note: No requirement to write whole HTML program. Just JavaScript code of need p

This work assesses the following Outcomes: • Build robust, secure distributed systems using advanced programming techniques Use RMI to build a distributed application accessing

Don''t know how to write this, can anyone help me? http://wikisend.com/download/660980/Moving Blobs.zip

The design of the website will be left to the individual student. The website must be written only in xml, displayed in xhtml using transforms and xsl for styling elements. Javascr