Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Write a Java Program to check if any number is a magic number or not.

public class IBMagicNumber{

   public static void main(String[] args) { 
       int num = 163;  
       int sumOfDigits = 0;
       while (num > 0 || sumOfDigits > 9) 
       { 
           if (num == 0) 
           { 
               num = sumOfDigits; 
               sumOfDigits = 0; 
           } 
           sumOfDigits += num % 10; 
           num /= 10; 
       } 

       // If sum is 1, original number is magic number 
       if(sumOfDigits == 1) {
           System.out.println("Magic number");
       }else {
           System.out.println("Not magic number");
       }
   }
}
Comment

PREVIOUS NEXT
Code Example
Java :: javax.net.ssl.trustStore trustall 
Java :: location.href webview android studio 
Java :: set the content of a Jlist from an other Jlist (Swing) 
Java :: convert kotlin code to java 
Java :: .code domain 
Java :: programme javascrip mineur et majaur 
Java :: AccountDriver.java 
Java :: java namespaces 
Java :: what is java.io example 
Java :: split email on dot java 
Java :: Calculator repeat 
Java :: preparestatement method in java 
Java :: error: package android.support.v4.content does not exist import android.support.v4.content.LocalBroadcastManager; 
Java :: sha1 
Java :: springBoot Register a Custom Auto-Configuration 
Java :: nonnull annotation in java 
Java :: java stack declaration 
Java :: acceder a elementos de list java 
Java :: oxygen cylinder management program in java 
Java :: javax.servlet.ServletException: javax.servlet.jsp.JspException: Missing message for key 
Java :: import classes from another project java 
Java :: write arraylist to outputstream java byte file 
Java :: spigot deal damage 
Java :: split() String android 
Java :: Unrolling java - after 
Java :: run app by package android 
Java :: Java throws clause 
Java :: add element to queue java 
Java :: free pearson uk textbooks 
Java :: stream get double value from map 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =