padovan string, Computer Engineering

Assignment Help:

how to write this program,what are the declaration and function are needed in java

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:- padovan string

Illustrate character coded data, Q. Illustrate Character Coded Data? Th...

Q. Illustrate Character Coded Data? The input output happens in the form of ASCII data. These ASCII characters are entered as a string of data. For illustration to get two numb

NETWORK ADMIN, Ask qDiscuss the risks of having a single root user and how ...

Ask qDiscuss the risks of having a single root user and how more limited management abilities can be given to others users on Linux/UNIX systems.uestion #Minimum 100 words accepted

Using bit wise operator implement nor and nand gate, Q. Write a program t...

Q. Write a program to implement NOR, NAND, XOR and XNOR gates using and without using bit wise operator. Also perform necessary checking. The user has option to give n numbe

Explain about indirect addressing, Q. Explain about Indirect Addressing? ...

Q. Explain about Indirect Addressing? In this technique the operand field of instruction specifies the address of address of intended operand for example if instruction LOAD

What is program controlled i/o, What is program controlled I/O? In prog...

What is program controlled I/O? In program controlled I/O the processor repeatedly checks a status flag to achieve the needed synchronization among the processor and an input a

Elements of information super highway infrastructure, Illustrate the elemen...

Illustrate the elements of Information Super Highway Infrastructure. The Information Superhighway is more than the Internet. This is a series of elements, including the collect

Can a structure be used within a structure, Can a structure be used within ...

Can a structure be used within a structure? Yes , a structure can be used within a structure known as nesting of structures.

Explain the method to identify the object classes, Explain the method to id...

Explain the method to identify the Object Classes You would always be careful while identifying relevant object classes from application domain. Objects may include physical e

Define syntax of mpi_scan function, Q. Define syntax of MPI_Scan  function...

Q. Define syntax of MPI_Scan  function? MPI_Scan (Sendaddr,, Receiveaddr , count, datatype, op, comm): It merges the partial values in p final results that are received in

For what DMSP stands, For what DMSP stands? DMSP stans here for Dist ri...

For what DMSP stands? DMSP stans here for Dist ributed Mai l system Protocol.

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