Computer Science, asked by Onesarthak007, 19 days ago

Write a menu driven Java program to input a number and check and display-
i. It is a Niven number or not.
[Hint: A number is a Niven number if it is divisible by the sum of its digits.]
ii. It is a Neon Number or not.
[Hint: A number is said to be a Neon number if the sum of the digits of the square of the number is equal to the number itself.]​

Answers

Answered by kamalrajatjoshi94
0

Program:-

import java.util.*;

class Program

{

public static void main(String args[])

{

Scanner in=new Scanner(System.in);

int n,ch;

System.out.println("Enter the number:");

n=in.nextInt();

System.out.println("Enter 1 to check a niven number");

System.out.println("Enter 2 to check a neon number");

ch=in.nextInt();

switch(ch)

{

case 1:

int s=0,a=0,num=0;

num=n;

while(n!=0)

{

a=n%10;

s=s+a;

n=n/10;

}

if(s==num)

System.out.println("It is a niven number");

else

System.out.println("It is a niven number");

break;

case 2:

int sum=0,n1=0,sq=0,r=0;

n1=n;

sq=n*n;

while(sq!=0)

{

r=sq%10;

sum=sum+r;

sq=sq/10;

}

if(sum==n1)

System.out.println("It is a neon number");

else

System.out.println("It is not a neon number");

break;

default:

System.out.println("Invalid choice");

}

}

}

Attachments:
Similar questions