Program to input a word and convert it into uppercase then print only characters at prime indexes JAVA


Write a Program to input a word and convert it into uppercase then print only characters at prime indexes.




import java.util.Scanner;
class primeprint
{
    public static void main()
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter a String");
        String s = sc.next().toUpperCase();
        int c =0;
        for(int i =2;i< s.length();i++)
        {
            for(int j =1;j<=i;j++)
            {
                if(i%j==0)
                c++;
            }
            if(c==2)
            System.out.print(s.charAt(i));
            c=0;
        }
    }
}

   
                     

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