Write a programme to check whether a number is a MAGIC number or not?

import java.util.*;
public class MagicNumberCheck
{
 public static void main(String args[])
 {
 Scanner ob=new Scanner(System.in);
 System.out.println("Enter the number to be checked.");
 int n=ob.nextInt();
 int sum=0,num=n;
 while(num>9)
 {
 sum=num;int s=0;
 while(sum!=0)
 {
 s=s+(sum%10);
 sum=sum/10;
 }
 num=s;
 }
 if(num==1)
 {
 System.out.println(n+" is a Magic Number.");
 }
 else
 {
 System.out.println(n+" is not a Magic Number.");
 }
 }
}

Comments

Post a Comment

Popular posts from this blog

ICSE Class 10 - Computer Application Important Program (15 Marks)

ICSE Class 10 - Computer Application Important Questions & Answers (2 Marks)

COMPUTER SCIENCE PRACTICAL SOLVED QUESTIONS - ISC BOARD 2018

Address Calculation in Single and Double Dimension Array - ISC Computer Science

ICSE CLASS 10 COMPUTER APPLICATION - Chapter 1: Concept of Objects

ISC Computer Science - Propositional Logic

COMPUTER SCIENCE PRACTICAL SOLVED QUESTIONS - ISC BOARD 2016

ICSE CLASS 10 COMPUTER APPLICATION - Chapter 2: The Java Phenomenon

Computer Science Paper 1 (Theory) - ISC 2018