83) Write a program to input a number and check whether it is Happy Number or not? (28=22+82=4+64=68,62+82=36+64=100,12+02+02=1+0+0=1)
import java.util.*;public class Happy_num{public static void main(String args[ ]){Scanner sc = new Scanner (System.in);System.out.println("Enter a number");int a = sc.nextInt();int s = 10;while(s>9){s=0;while(a>0){int d = a%10;int x = (int)Math.pow(d,2);a = a/10;s=s+x;}a=s;}if(s==1){System.out.println("Entered number is a HAPPY Number");}else{System.out.println("Entered number is not a HAPPY Number");}}}
Output :
happy-number Write a program to input a number and
check whether it is Magic Number or
not? ( 64 = 6+4 = 10 = 1+0 = 1) |