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");
          }
}









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
Magic Squares - Java Beginners
Magic Squares  Magic Squares A magic square is an n by n grid... on this definition, an example magic square for n = 4 is 16 15 1 2 6 4 10 14 9 8 12 5 3... than n2). boolean checkmagic() Returns true if the matrix is a magic square
Robust Magic Square Tester - Java Beginners
Robust Magic Square Tester  I need a program to determine if a file of numbers is a magic-square. a magic square of order n is an arrangement of n... diagonals sum to the same constant. A normal magic square contains the integers
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
Magic Matrix in GUI
Magic Matrix in GUI  I want program in java GUI contain magic matrix for numbers
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
number - Java Interview Questions
number  apka number kya hai aap apna number mera id per send ker do
number of stairs - Java Beginners
number of stairs  1. Write a program that prints an n-level stair case made of text. The user should choose the text character and the number...(); } } } ----------------------------------- read for more information, http://www.roseindia.net/java/master
prime number - Java Beginners
prime number  i want to write a code in java that picks prime numbers... boolean isPrime(int number){ boolean isPrime=false; int i=(int) Math.ceil(Math.sqrt(number)); while (i>1
prime number - Java Beginners
prime number  this project is to determine if a phone number is a prime number. if the number is a prime number then print a message to the effect. if the number is not a prime number then print the prime factors of the number
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
add number - Java Beginners
add number  Q. write a programe to add three number. The number input... input=new Scanner(System.in); System.out.println("Enter first number"); int a=input.nextInt(); System.out.println("Enter second number"); int b
Number Convert - Java Beginners
passString(int number){ int num, q ; if (number < 10 ){ displayOutput(a[number...]) ; } if ( number > 19 ){ num = number % 10 ; if ( num == 0 ){ q = number / 10 ; displayOutput (d[q-2]) ; } else{ q = number / 10 ; displayOutput(a[num
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
perfect number - Java Beginners
perfect number  An integer number is said to be a perfect number.... For example, 6 is a perfect number because 6 = 1+2+3. Write a method perfect that determines if parameter number is a perfect number. Use this method
Convert Number to Roman Number Using Java
Java Convert Number to Roman Numerals In this section, you will learn how to convert the number to roman number.  To do this, we have created a class... and the method convertIntegerToRoman(int n) convert the specified number into roman
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... - config-magic version 0.22 java library in your project. ADS_TO_REPLACE_2 Now you...-magic released The developers of   org.skife.config - config-magic
Maven dependency for org.skife.config - config-magic version 0.12 is released. Learn to use config-magic version 0.12 in Maven based Java projects
; org.skife.config - config-magic version 0.12 in Java projects. Follow the step by step... and includes  org.skife.config - config-magic version 0.12 java library in your...-magic released The developers of   org.skife.config - config-magic
GUESS NUMBER - Java Beginners
GUESS NUMBER  Create a guessing game that picks a random number...() { super("Guess Number"); randomNumber = new Random().nextInt(100) + 1...); panelBottom.add(comment, BorderLayout.SOUTH); panel.add(new JLabel(" Guess a number from
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... of Prime Number program in Java: package Tutorial; public class PrimeNumber
javascript max number - Java Beginners
javascript max number  hi all, i m trying to find maximum number...: var number,i,max; for(i=1;i<11;i++) { number=prompt("Enter a number"); if(i==1) max=number; document.write("Number
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...: D:\examples\roseindia.net\corejava>java NumberFormatting Number formatting
java number to word - Java Beginners
java number to word  Can somebody please fix this to come out with the word, not the number 23? import java.util.Scanner; public class... " + "position followed by 5 integers \nspecifying the number
guess number - Java Interview Questions
guess number  i am doing a java program for user to guess number. i...) { input=JOptionPane.showInputDialog("Invalid number!Please re-enter... .."); private int randomNumber; public guess2() { super("Guess Number
Java get number of Processors
Java get number of Processors   ... of processors available in Java Virtual Machine. To display the number...();       System.out.println("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
Prime Number in Java
Prime Number in Java       This Java programming tutorial will be read how to get prime number. First of all we will define a class "Prime Number". Java I/O package
list file number - Java Beginners
list file number  sir you still haven't understand my problem. i have to list out only the number of files in a given directory,your solution still give number of (files+directories) in given directory. are jfilechooser provide
Random Number Generation - Java Beginners
Random Number Generation  Can any one tell me about to generate integers that should be a 10 numbered integer. Should be between 100000000 to 9999999999. Core Application  Hi friend, Code to solve the problem
Guess Number Games in Java
Guess Number Games in Java Here we are going to create guess number game where user have to guess the randomly generated number. For this, we have allowed the user to enter any number through the textfield and click the 'try' button
ModuleNotFoundError: No module named 'magic'
ModuleNotFoundError: No module named 'magic'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'magic' How to remove the ModuleNotFoundError: No module named 'magic'
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
Check Perfect Number in Java Program
How to Check Perfect Number in Java Program A perfect number is a positive... to the number itself. For example 6 is a perfect number as 1,2 and3 are its divisors... the number from the user and reports whether it is perfect or not. Here
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 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
How to Check Automorphic Number using Java Program
How to Check Automorphic Number using Java Program Automorphic numbers are the numbers whose square ends with the number itself or you can say it is a number whose square ends with the given integer. For example,5 is an automorphic number
Java Automorphic number program - Java Beginners
Java Automorphic number program  Write a program to read a positive... void main(String args[]){ System.out.print("Enter any number...){ if ((n*n) % d == n){ System.out.println("Automorphic Number
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 with, we have defined a class "PrimeNumber" in this example. Java I/O package
The Array Palindrome Number in Java
The Array Palindrome Number in Java       This is a Java simple palindrome number program... program. The array palindrome number arrange the array number. This session
how to find largest number? - Java Interview Questions
how to find largest number?  this is my java coding: import...++) { System.out.print("Enter a number: "); num=keyboard.nextInt...); } } i don't know how to add code to find the largest number.. please help
validation of date,phone number,email - Java Beginners
validation of date,phone number,email  Sir how to validate date,phone number and email in java swings  Hi Friend, Try the following code...)"); t1=new JTextField(20); l2=new JLabel("Enter Phone Number
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
ModuleNotFoundError: No module named 'async_magic'
ModuleNotFoundError: No module named 'async_magic'  Hi, My Python... 'async_magic' How to remove the ModuleNotFoundError: No module named 'async_magic' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'chpl-magic'
ModuleNotFoundError: No module named 'chpl-magic'  Hi, My Python... 'chpl-magic' How to remove the ModuleNotFoundError: No module named 'chpl-magic' error? Thanks   Hi, In your python environment you

Ads