Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
219 views

Good Number (JAVA PROGRAM PDF

JAVA PROGRAM TO CHECK IF 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 ). WITH COMMENTS AND DETAILS TO HELP YOU UNDERSTAND THEM.THIS PROGRAM HAS BEEN RUN ON BlueJ AND IS ERROR FREE.IT WILL SURELY HELP YOU IN STUDYING JAVA PROGRAMS FOR EXAMS OR OTHERWISE.

Uploaded by

AMRENDRA SINGH
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
219 views

Good Number (JAVA PROGRAM PDF

JAVA PROGRAM TO CHECK IF 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 ). WITH COMMENTS AND DETAILS TO HELP YOU UNDERSTAND THEM.THIS PROGRAM HAS BEEN RUN ON BlueJ AND IS ERROR FREE.IT WILL SURELY HELP YOU IN STUDYING JAVA PROGRAMS FOR EXAMS OR OTHERWISE.

Uploaded by

AMRENDRA SINGH
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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