Define a class PrintPrime with the following specification
Class Name    PrintPrime
Data members 
String str , int c
Member Functions

void getdata() - to input string without spaces
void printp(int p , int q)  Print only prime location character in one string recursively.

Eg i/p PROGRAM
    o/p OGA

Also write main function
            




import java.util.Scanner;
class PrintPrime 
{
    String str;
    int c;
    void getData() 
    {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter a string without spaces: ");
        str = sc.next();
        c = str.length(); 
    }
    void printp(int p, int q) 
    {
        if (p == q) 
        {
            return; 
        } else 
        {
            int count = 0;
            for (int i = 2; i < p; i++) 
            {
                if (p % i == 0) 
                {
                    count++;
                }
            }
            if (count == 0) 
            {
                 System.out.print(str.charAt(p));
            }
            printp(p + 1, q);
        }
    }
    public static void main(String args[]) 
    {
        PrintPrime obj = new PrintPrime();
        obj.getData();
        obj.printp(2, obj.c);
    }
}




     
                     

Contact Us

REACH US

SERVICES

  • CODING
  • ON-LINE PREPARATION
  • JAVA & PYTHON

ADDRESS

B-54, Krishna Bhawan, Parag Narain Road, Near Butler Palace Colony Lucknow
Contact:+ 919839520987
Email:info@alexsir.com