Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Magic number in java
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


R Radhika
Magic number in java
1 Answer(s)      3 years and 6 months ago
Posted in : Java Beginners


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


Advertisement
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
Magic Matrix in GUI
Magic Matrix in GUI  I want program in java GUI contain magic matrix for numbers
PHP Magic Constant
PHP Magic Constants: In PHP there are various predefined constants, but many... of the magic constants are as follows: 1) __LINE__: This constant is used to indicate the current line number of the file. 2) __DIR__ :  This constant is used
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
PHP Magic Methods
Magic Methods in PHP: In PHP there are so many methods are included in recent versions, magic methods are one of them. The magic methods are listed below..._state() __clone() In the above list of the magic methods it is very
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
number - Java Interview Questions
number  apka number kya hai aap apna number mera id per send ker do
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
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
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
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
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
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
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
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
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
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
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
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...("Number of processors available to the Java Virtual Machine
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
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
Advertisements
 

 

 

DMCA.com