Computer Science, asked by Shrieya, 1 year ago

Write a java program to check whether the entered number is kaprekar number or not. USING java.util.*; and Scanner.

Answers

Answered by Anonymous
3
import java.io.*;

import java.util.*;

class coding

{    public static void main(String args[])throws IOException

    {        BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));

        String s=""; int ch1=32; char c; int i;

        System.out.print("Input (coded text)\t: ");

        String cod=buf.readLine();

        int length=cod.length();

        int ch=0,a1=2,flag=0;

        for (int a=0;a<=(length-1);)

        {  ch=(Integer.parseInt(cod.substring(a,a1)));

            if(((ch>=65)&&(ch<=90))||(ch==32)||((ch>=97)&&(ch<=122)))

            {  if (ch1==32)

                {  ch=((ch>=65)&&(ch<=90))? ch:(ch-32);

                       if (ch==32)

                        continue;                }

                else

                    ch=((ch>=65)&&(ch<=90))? (ch+32):ch;

                c=(char)ch;

                s=s+c;

                ch1=ch;

                a+=(flag==0)?2:3;

                a1+=2;

                flag=0;            }

            else

            {  if(flag==0)

                {  a1++;

                    flag=1;

                    continue;      }

                else

                {  flag=0;

                    a+=2;

                    a1++;

                    continue;                }           }        }

        System.out.print("Output(decoded text)\t: ");

        StringTokenizer st=new StringTokenizer(s);

        for (i=0;st.hasMoreTokens();i++)

            System.out.print ((st.nextToken()).trim()+" ");    }


Shrieya: Thanks a lot
Similar questions