Magic number in java

Magic number in java

Hi.. Can any one tel how to watch a magic number of a program?

View Answers

June 27, 2011 at 12:41 PM

import java.util.*;

 class MagicNumber{

    public int divide(int x){
    int a,b=0;
    for(int i=x;i>0;i/=10){
    a=i%10;
    b+=a;
    }
    return b;
    }

   public static void main(String[]args)throws Exception{
        Scanner input=new Scanner(System.in);
        System.out.print("Enter the number: ");
        int num =input.nextInt();
        int b=0,x=1;
        MagicNumber l=new MagicNumber();
          do{
           if(x==1){
            b=l.divide(num); x++;
           }
           else{
            b=l.divide(b);
           }
          }
          while((b/10)>0);
          if(b==1)
          System.out.print("Magic Number");
          else
          System.out.print("Not a Magic Number");
          }
}

Ads









Related Tutorials/Questions & Answers:
Magic number in java
Magic number in java  Hi.. Can any one tel how to watch a magic...==1) System.out.print("Magic Number"); else System.out.print("Not a Magic Number
Magic number Java Program
Magic number Java Program  write a program that guesses what number the user is thinking of. Below is a sample transcript: Think of a number between 1 and 255. I will guess the number you are thinking of. 1 3 5 7 9 11 13 15 17
Advertisements
How to format number in Java?
How to format number in Java?  Hi, What is the best way to format a number in Java? How to format number in Java? Thanks   Hi, To format number in Java you can use the class java.text.NumberFormat. Here is simple
getting random number in java
getting random number in java  getting random number in java Hi... and scaling the random number in my Java Random number eample. but for some reason... to generate the random number in Java Thanks in Advance
Write a program in Java to convert Decimal number into Binary number
Write a program in Java to convert Decimal number into Binary number  Hi, I have decimal number and I want to convert it to Binary. How to Write a program in Java to convert Decimal number into Binary number? Thanks
program on factorial of a given number in java
program on factorial of a given number in java  please tell me, how to write program on factorial of a given number in java
program on factorial of a given number in java
program on factorial of a given number in java  please tell me, how to write program on factorial of a given number in java
Java reverse number
Java reverse number In this tutorial, you will learn how to reverse a number in java. In java, you can use arithmetic operators like division operator(/) and remainder operator(%) to reverse the number. The division operator returns
java code for swaping two number
java code for swaping two number  how to code for swaping two number without taking third variables
Prime Number program in Java
Prime Number program in Java will print the prime numbers between 1 to any given number. Prime Number is a number that is not divisible by any number other... automatically prints Prime Number starting from 1 to 50. Example of Prime Number
Magic Matrix in GUI
Magic Matrix in GUI  I want program in java GUI contain magic matrix for numbers
How to format number in Java?
Learn about the code of formatting the number in Java This tutorial explains you how to format the number in Java. There are number of situations where we need the number to be formatted in many different formats. Depending the format
Java get number of Processors
Java get number of Processors   ... of processors available in Java Virtual Machine. To display the number...("Number of processors available to the Java Virtual Machine
how to create month wise serial number in java?
how to create month wise serial number in java?  Ex: For 1)January-serial number is 1/001,1/002,1/003 etc
How to round a number to n decimal places in Java
How to round a number to n decimal places in Java  How to round a number to n decimal places in Java
Java Number Format
Java Number Format      ... the format of the number. In java this is achieved by the java.text.NumberFormat class. NumberFormat is the abstract base class for all number formats
prime number question - Java Beginners
prime number question  For the question located here: http://www.roseindia.net/answers/viewanswers/5778.html How do you make it so that the user has to input the two numbers and it displays the prime numbers within the range
Maven dependency for org.skife.config - config-magic version 0.22 is released. Learn to use config-magic version 0.22 in Maven based Java projects
- config-magic version 0.22 in Java projects. Follow the step by step tutorial...-magic released The developers of   org.skife.config - config-magic..., the released version of  org.skife.config - config-magic library is 0.22. Developer
Prime number program in java
Prime number program in java In this example you will learn how to write a program to generate and check  prime number  in java. As we know prime number are those number which are divisible by 1 or itself, first define
Prime Number in Java
Prime Number in Java In this Java tutorial , you will learn how to write a Java program to get prime numbers between 1 to the desired number. To start... prime number. ADS4ThUnitADS Here is the code of the java Program to get prime
Formatting number as per specific locale in java
Formatting number as per specific locale in java  Hi, I am trying to print the number as per locale. I tried below, but it still prints in English...(Locale.getDefault()); //returns zh. //format the number as per locale -->
prime number
prime number  get one number and check the number prime or not using if statement   Java Check Prime Number
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
prime number
prime number  check prime number using if statement   Java Check Prime Number
prime number
prime number  check prime number using if statement   Java Check Prime Number

Ads