Computer Science, asked by Ashvi16, 1 year ago

WAP A Menu driven program to enter a number and check whether it is a unique number or not or automorphic number or not
(in java)


QGP: Does automorphic mean that the number is contained in the last digits of its square?
Ashvi16: yea..exactly
Ashvi16: like 25 n 625
QGP: Yeah. You in ICSE?
QGP: Are you studying in ICSE? I thought because I have seen a book of ICSE , which uses BlueJ , and contains similar programs
Ashvi16: yea u got it
QGP: I will be doing it at night, as I'm currently on mobile
Ashvi16: ok fine

Answers

Answered by QGP
34
import java.util.*;
public class Brainly
{
    void automorph(int n)
    {
        int d=0,m,f;
        double p;

        m=n;

        while (m!=0)
        {
            m=m/10;
            d++;
        }

        m=n*n;
        p = m%(Math.pow(10,d));

        System.out.println(n+"*"+n+"="+m);

        if (n==p)
            System.out.println(n+" is an Automorphic number.");
        else
            System.out.println(n+" is not an Automorphic number.");
    }

    void unique(int n)
    {
        int l,i,j,f=0;
        String s;

        s = Integer.toString(n);
        l = s.length();

        for(i=0;i<l;i++)
        {
            for(j=0;j<i;j++)
            {
                if (s.charAt(i)==s.charAt(j))
                {
                    f=1;
                    break;
                }
            }
            if (f==1)
                break;
        }

        if(f==0)
            System.out.println(n+" is a Unique number.");
        else
            System.out.println(n+" is not a Unique number.");
    }

    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);

        int ch,n;

        System.out.println("1) To check for Unique Number");
        System.out.println("2) To check for Automorphic Number");
        System.out.print("Enter your choice: ");
        ch = in.nextInt();

        Brainly ob = new Brainly();

        switch(ch)
        {
            case 1:
                    System.out.print("Enter number: ");
                    n = in.nextInt();
                    ob.unique(n);
                    break;

            case 2:
                    System.out.print("Enter number: ");
                    n = in.nextInt();
                    ob.automorph(n);
                    break;

            default:
                    System.out.println("Invalid Choice.");
                    break;
        }
    }
}                
Answered by 8863970297avi
4

Answefuck

Explanation:

Similar questions