Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Happy Numbers in Java
import java.util.Scanner; class Rextester { public static void main(String args[]) { int n = new Scanner(System.in).nextInt(), sum = n; if(n == 7 || n == 1) System.out.println("It's happy number!"); while(sum > 9) { sum = 0; while(n != 0) { sum += (n % 10) * (n % 10); n /= 10; } System.out.println(sum); n = sum; } if(n == 1 || n == 7) System.out.println("It's a happy number!"); else System.out.println("It's not a happy number"); } } // PROGRAM BY 'JAMES COLLINS'
run
|
edit
|
history
|
help
0
Java Array List
boundary vs core
home by stars
1a
"encryption"
Feet-inches input validation
UserDefinedBar
Cyclically rotate array
ElaineBrown**
swastik