0% found this document useful (0 votes)
39 views2 pages

Class Perfect: / Question Design A Program in Java To Check Whether A Number Is A PERFECT Number or Not.

JAVA PROGRAM TO FIND THE TRANSPOSE OF A MATRIX (A transpose of an array obtained by interchanging the elements of the rows and columns) . 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
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views2 pages

Class Perfect: / Question Design A Program in Java To Check Whether A Number Is A PERFECT Number or Not.

JAVA PROGRAM TO FIND THE TRANSPOSE OF A MATRIX (A transpose of an array obtained by interchanging the elements of the rows and columns) . 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
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Class perfect

1/1

/**
* QUESTION
*
* Design a program in java to check whether a number
* is a PERFECT number or not.
*/
import java.io.*;
public class perfect
{
public int digit_count(int n)throws IOException
/** method to count no of digts in a number */
{
int c=0;
int m=n;
//creating dummy variable
while(m>0)
{
c=c+1; //counter variable
m=m/10; //updating loop variable
}
return c; //returning no of digits
}//end of digit_count
public void main()throws IOException
{
DataInputStream d=new DataInputStream(System.in);
System.out.println("enter the number");
int n=Integer.parseInt(d.readLine());
int c=digit_count(n);
//counting digits
int p=(int)Math.pow(n,2);
//squaring the number
int e=(int)Math.pow(10,c);
int ex=p%e;
//extracting c no of digits from end of square of number
if(ex==n)
{
System.out.println("The number is a PERFECT number");
}
else
{
System.out.println("The number is not a PERFECT number");
}
}
}

Jan 16, 2015 10:59:04 PM

perfect1.main();
enter the number
25
The number is a PERFECT number
perfect1.main();
enter the number
35
The number is not a PERFECT number

You might also like