fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Scanner sc = new Scanner(System.in);
  13.  
  14. System.out.println("Enter number: ");
  15. int n = sc.nextInt();
  16.  
  17. int l = String.valueOf(n).length();
  18. int temp=n;
  19.  
  20. int midVar=0, addVar=0, i=0;
  21.  
  22. while (temp!=4)
  23. {
  24. midVar=0;
  25.  
  26. for (i=l; i>0; i--)
  27. {
  28. addVar = temp/Math.pow(10, i);
  29. midVar+=Math.sqrt(addVar);
  30. }
  31.  
  32. temp = midVar;
  33.  
  34. if (temp==1)
  35. break;
  36. }
  37.  
  38. if (temp==1)
  39. {
  40. System.out.println("Happy number");
  41. }
  42. else
  43. {
  44. System.out.println("Unhappy number");
  45. }
  46. }
  47. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
68
compilation info
Main.java:28: error: incompatible types: possible lossy conversion from double to int
            addVar = temp/Math.pow(10, i);
                         ^
1 error
stdout
Standard output is empty