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

Assignment Help:

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


Related Discussions:- n-th padovan string p(n)

Help, I can''t figure out how to do this question: "Given two linear equati...

I can''t figure out how to do this question: "Given two linear equations: ax + by + c = 0 and dx + ey + f = 0" solve for x and y. A, b, c, d, e, and f being inputted from the user.

Data structure of different delimiters, In this experience you will make th...

In this experience you will make the neophyte Java programmer happy by solving, to a limited extent, an age-old problem in programming:  mismatched delimiters.  As we all know, eve

GUI, I have a GUI assignment due Friday noon and i can''t get my hand on it...

I have a GUI assignment due Friday noon and i can''t get my hand on it will anyone be able to solve it to me and what is the cost?

Difference between ejb 2.0and ejb 1.1, EJB 2.0 has the additional advantage...

EJB 2.0 has the additional advantages over the EJB 1.1 given below 1. Local interfaces : These are beans that can be needed locally, that means by the same Java Virtual Machi

What is documentation for the class library, What is Documentation for the ...

What is Documentation for the class library Sun gives a large amount of documentation for the classes, interface's and exceptions in the class library. If you've installed the

Ocr captcha solving, I'm seeking to hire someone to build me a program that...

I'm seeking to hire someone to build me a program that can solve a php captcha. It should be a web service or script. You will write it in any language since i will execute i ca

What is includeaction, The IncludeAction class is useful when you require t...

The IncludeAction class is useful when you require to integrate Struts into an application that uses Servlets. Use the IncludeAction class to contain another resource in the respon

Extraction of articles, Extraction of articles The software I'm looking ...

Extraction of articles The software I'm looking to build: 1. Extraction of articles from various sites 2. Format the content to re-post 3. Automate the process Skill

Difference between composition and aggregation, Aggregation Comp...

Aggregation Composition Aggregation :  An   association   in  which  one  class refers to collection or a another class. This is a part of  a  who

Package, how to write bank system

how to write bank system

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd