Thursday, November 10, 2016

Mystic Number Program Using BlueJ




What is mystic number?


A mystic number is a number whose sum of the digits is 3. Point to be noted that the adding of the digits continue till it becomes 3.

For example, 552 is a mystic number. 5 + 5 + 2= 12 and again 1+2 = 3.

import java.io.*;
class Pat
{
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
 int n,sum;

public void show() throws Exception
{

System.out.print("Enter the number :");
n=Integer.parseInt(br.readLine());

while(n >9)
{
 sum=0;
while(n >0)
{
 sum+=n%10;
n=n/10;
}
 n=sum;
}
if(n==3)
System.out.println("\nThe number is a mystic number.");
else
System.out.print("The number is not a mystic number.");
}
public static void main(String args[])throws Exception
{
 Pat ob=new Pat();
ob.show();
}
}

Related PostBlueJ Programs on Number

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner