Good Number (JAVA PROGRAM pdf)
-
Upload
amrendra-singh -
Category
Documents
-
view
228 -
download
0
Transcript of Good Number (JAVA PROGRAM pdf)
-
7/27/2019 Good Number (JAVA PROGRAM pdf)
1/1
Class good_number 1/1
/*
* 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
*/
importjava.io.*;
publicclassgood_number
{
publicvoidmain()throws IOException
{
DataInputStream d=newDataInputStream(System.in);
System.out.println("enter the number");
int a=Integer.parseInt(d.readLine());
doublec=0;
//variable to store sum of reciprocals of digits
intm=a;
//creating dummy variable
doubler=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