Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Class good_number 1/1

/*
* ashking13th@gmail.com
* javaprogramsbyashking13th.blogspot.in
* ashkingjava.blogspot.in
*
* QUESTION
*
* Design a program in java to check whether a number is
* a good number or not.
* A good number is a number in which the sum of reciprocals
* of every digit equals 1.
* eg,
* 22 -- 1/2 +1/2 =1
* 333 -- 1/3 +1/3 +1/3 =1
*/
import java.io.*;
public class good_number
{
public void main()throws IOException
{
DataInputStream d=new DataInputStream(System.in);
System.out.println("enter the number");
int a=Integer.parseInt(d.readLine());
double c=0;
//variable to store sum of reciprocals of digits
int m=a;
//creating dummy variable
double r=0;
while(m>0)
{
r=m%10;
c=c+(1/r);
/*
* finding the sum of reciprocals of the digits of the
* inputed number.
*/
m=m/10;
}
/*
* if the sum is equal to 1 then the number is
* good number.
*/
if(c==1)
{
System.out.println("its a good number");
}
else
{
System.out.println("its not a good number");
}
}//end of main
}//end of clss
Mar 25, 2014 3:29:45 PM

You might also like