---
title: "Happy numbers in java"  
description: "In this blog I am provide you the code for Generating Happy numbers in java.import java.io.*;   class HappyNumbers                    static Buffered"  
author: "Vijay Shukla"  
published: 2013-10-04  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/594/happy-numbers-in-java  
category: "java"  
tags: ["java"]  
reading_time: 3 minutes  

---

# Happy numbers in java

In this [blog](https://www.mindstick.com/articles/12705/myths-and-misconception-about-blog) I am provide you the [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) for Generating Happy numbers in java.

```
import java.io.*;
class HappyNumbers{                static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                int n;                HappyNumbers()                {                                n=0;                }
                void getnum(int nn)                {                                n=nn;
                }                int sum_sq_digits(int x)                {                                if(x==0)                                    return 0;                        else                                {                                    int d=x%10;                                    return (d*d+ sum_sq_digits(x/10));                                }
                }                void ishappy()                {                                int a=sum_sq_digits(n);                                while(a>9)                                {
                                                a=sum_sq_digits(a);                                }                                if(a==1)                                   System.out.print(n+" is a Happy Number");                                else                                   System.out.print(n+" is Not a Happy Number");
                }                public static void main(String[] args)throws IOException                {                                HappyNumbers ob=new HappyNumbers();                                System.out.print("Enter any number: ");                                int b=Integer.parseInt(br.readLine());                                ob.getnum(b);                                 ob.ishappy();                }
}
```

\

##### Output: -

![Happy numbers in java](https://www.mindstick.com/blogs/fae22389-8b5d-432b-890f-a6f19d4f2b92/images/fad6eea0-3145-479e-a1bc-e1e6cb5758c6.png)

---

Original Source: https://www.mindstick.com/blog/594/happy-numbers-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
