hi, i m very new here and also in programming world. i tried to make a program that prints happy and unhappy numbers. but that prints only unhappy numbers and then it goes back to while loop where j remain 0. how can i fix the problem? plz someone help me.

``````import java.util.*;
public class HappyNumber{
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();

int [] a = new int [1000];
a[0] = x;
double sum = 0;
int j = 0;
int p = 0;
while( j<1000){
x = a[j];
for(int i = 0; x>0; i++){
int m = x%10;
x = x/10;
sum = sum + Math.pow(m,2);
p = (int)sum;
}
a[j+1] = p;

if(a[j+1]==0){
System.out.println(a[0] +" is a Unappy number");
break;
}else if(a[j+1]==4){
System.out.println(a[0] +" is a Unappy number");
break;
}else if(a[j+1]==16){
System.out.println(a[0] +" is a Unappy number");
}else if(a[j+1]==20){
System.out.println(a[0] +" is a Unappy number");
}else if(a[j+1]==37){
System.out.println(a[0] +" is a Unappy number");
}else if(a[j+1]==42){
System.out.println(a[0] +" is a Unappy number");
}else if(a[j+1]==58){
System.out.println(a[0] +" is a Unappy number");
}else if(a[j+1]==89){
System.out.println(a[0] +" is a Unappy number");
}else if(a[j+1]==145){
System.out.println(a[0] +" is a Unappy number");
}else if(a[j+1]==1){
System.out.println(a[0] +" is a Happy number");
}else{
j++;
}
}
}
}
``````

You didn't explain what happy vs. unhappy is. And you didn't post your code in code tags.