WAP in JAVA!!! ❤❤☺☺
#suⓂ️edhian ❤❤
Attachments:
Answers
Answered by
7
import java.util.Scanner;
public class happy{
public static void main(String[] srgs){
Scanner in = new Scanner(System.in);
System.out.println("Enter a number: ");
int num = in.nextInt(),ctr=0,c=num,sum=0,rem;
while(num!=0){
c=c/10;
ctr++;
}
for(int i=0;i<=ctr;i++){
rem=num%10;
sum+=rem;
num=num/10;
}
int a=sum;
while(a!=0){
a=a/10;
ctr++;
}
for(int i=0;i<=ctr;i++){
rem=sum%10;
num+=rem;
sum=sum/10;
}
if(num==1)
System.out.print("happy number");
else
System.out.print("not happy number");
}
}
Similar questions