Computer Science, asked by schoolhater26, 10 months ago

JAVA PROGRAM :WAP to accept a number and determine if it is a happy number . A perfect number is a positive integer that is equal to the sum of its proper positive divisors excluding the number itself. Examples :1,2,4,7,14 and 28

Answers

Answered by serenelynkharkrang
2

Answer:

import java.util.*;

class happy_number

{

public static void main()

{

Scanner sc = new Scanner (System.in);

int n,s=0,d;

System.out.println("ENTER A NUMBER:");

n=sc.nextInt();

s=n;

do

{

n=s;

s=0;

do

{

d=n%10;

s=s+d*d;

}

while(n>0)

}

while(s>9)

if (s==1)

System.out.println("HAPPY NUMBER");

else

System.out.println("NOT A HAPPY NUMBER");

}

}

Explanation: if you go through the program, it's pretty self-explanatory. I hope it helps! :))

Similar questions