perfect number

perfect number

An integer number is said to be a perfect number.... For example, 6 is a perfect number because 6 = 1+2+3. Write a method perfect that determines if parameter number is a perfect number. Use this method in an application

View Answers

April 10, 2008 at 7:33 PM

hi friend

import java.io.*;
import java.io.BufferedReader;

public class PerfectNumber{

public static void main(String[] args) throws IOException{
BufferedReader buff =new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter numerical value!");
String str = buff.readLine();
int x = Integer.parseInt(str);
for (long n=1; true; n = n + x) {
long sum = 0;
for (long i = 1; i < n; i++)
if (n % i == 0)
sum = sum + i;
System.out.println("The sum of the divisors of " + n + " is " + sum);
if (sum == n)
break;
}
}
}









Related Tutorials/Questions & Answers:
perfect number - Java Beginners
perfect number  An integer number is said to be a perfect number.... For example, 6 is a perfect number because 6 = 1+2+3. Write a method perfect that determines if parameter number is a perfect number. Use this method
Check Perfect Number in Java Program
How to Check Perfect Number in Java Program A perfect number is a positive... to the number itself. For example 6 is a perfect number as 1,2 and3 are its divisors... the number from the user and reports whether it is perfect or not. Here
Advertisements
Perfect Numbers - Java Beginners
Perfect Numbers  The number 6 is said to be a perfect number because it is equal to the sum of all its exact divisors (other than itself). 6 = 1 + 2 + 3 Write a java program that finds and prints the three smallest perfect
ModuleNotFoundError: No module named 'perfect'
ModuleNotFoundError: No module named 'perfect'  Hi, My Python... 'perfect' How to remove the ModuleNotFoundError: No module named 'perfect... to install padas library. You can install perfect python with following command
ModuleNotFoundError: No module named 'perfect-hash'
ModuleNotFoundError: No module named 'perfect-hash'  Hi, My Python... 'perfect-hash' How to remove the ModuleNotFoundError: No module named 'perfect-hash' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'perfect-jsonschema'
ModuleNotFoundError: No module named 'perfect-jsonschema'  Hi, My... named 'perfect-jsonschema' How to remove the ModuleNotFoundError: No module named 'perfect-jsonschema' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'perfect-pypi'
ModuleNotFoundError: No module named 'perfect-pypi'  Hi, My Python... 'perfect-pypi' How to remove the ModuleNotFoundError: No module named 'perfect-pypi' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'perfect_html'
ModuleNotFoundError: No module named 'perfect_html'  Hi, My Python... 'perfect_html' How to remove the ModuleNotFoundError: No module named 'perfect_html' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'perfect-game-player'
ModuleNotFoundError: No module named 'perfect-game-player'  Hi, My... named 'perfect-game-player' How to remove the ModuleNotFoundError: No module named 'perfect-game-player' error? Thanks   Hi
buzz number
buzz number  buzz number
prime number
prime number  get one number and check the number prime or not using if statement   Java Check Prime Number
the number of parameters
the number of parameters  How do I find out the number of parameters passed into function
Number in array
Number in array  How to write a program to check the number that we are entered from keyboard is in the given array
prime number
prime number  check prime number using if statement   Java Check Prime Number
prime number
prime number  check prime number using if statement   Java Check Prime Number
prime number
prime number  To check a number entered by user is prime or not?   Java check prime number import java.util.*; class CheckPrimeNumber { static boolean isPrime(int number){ boolean isPrime=false
prime number
prime number  could u pls help me out in finding whether a number is a prime number or not?   import java.util.*; class CheckPrimeNumber { static boolean isPrime(int number){ boolean isPrime=false
prime number
prime number  To check a number entered by user is prime
Armstrong number
Armstrong number  I want java program for Armstrong number
prime number
prime number  write a java program for prime number
prime number
prime number  to check wethere given number is prime or not?  ... { static boolean isPrime(int number){ boolean isPrime=false; int i=(int) Math.ceil(Math.sqrt(number)); while (i>1
prime number
prime number  HI!I want a java program that accepts a number from user and displays whether it is a prime number or not using BufferedReader
Count number of "*"
Count number of "*"  I have this code to count the number of * from a string entered. but I need to find it from an text file. Any idea? import...++; } } System.out.println("The number of vowels in the given sentence
Number Pyramid
Number Pyramid  Hi Everyone, Can someone help me write the code for the following number pyramid: print... 0 0 0 0 4 ... "); There is 5 spaces in between each number
number sorting
number sorting  program to sort a list of numbers in descending order where the inputs are entered from keyboard in runtime   Hi Friend, Try the following code:ADS_TO_REPLACE_1 import java.util.*; class
number pyramid
number pyramid   how to get the code for the following : 1 123 12345 1234567   class Pyramid{ public static void main(String args[]){ for(int i=1;i<=7
Primary number
Primary number  write a program to find the 100th or nth primary number?   import java.util.*; class PrimeNumber{ public static void main(String a[]) { Scanner input=new Scanner(System.in
random number
random number   Please How do I generate a program that gives me random integer from 115 to 250? Using java.util.random. Thank you very much!   Hi Friend, Try the following code:ADS_TO_REPLACE_1 import java.util.
Primary number
Primary number  write a program to find the 100th or nth primary number?   import java.util.*; class PrimeNumber{ public static void main(String a[]) { Scanner input=new Scanner(System.in
MySQL random number
is not a perfect random number but it is very close to the perfect random numbers. Here... MySQL random number       You may fall in the condition when you want to create random number for your
VoIP Number
VoIP Number VoIP Numbers With a VoIPtalk Incoming number, callers can reach you by calling a UK number no matter where you are, Simply plug... connection and anyone can reach you by dialling your individual number. The VoIPtalk
to read number from user
to read number from user  1)print the positive equivalent of the number 2) check if the no is integer or not 3) find the square root of the number 4) find the cube of the number
number - Java Interview Questions
number  apka number kya hai aap apna number mera id per send ker do
NUMBER OF VOWELS IN A WORD
NUMBER OF VOWELS IN A WORD  WRITE A PROGRAM THAT WILL INPUT A WORD THEN IT WILL DETERMINE THE NUMBER OF VOWELS PRESENT IN THE INPUTTED WORD
using random number
using random number  generate a 10 digit number using random number and display the length of longest increasing series
To check a palindrome number?
To check a palindrome number?  program to check a number is palindrome or not using recursion?(wihout converting to string
ModuleNotFoundError: No module named 'is-number'
ModuleNotFoundError: No module named 'is-number'  Hi, My Python... 'is-number' How to remove the ModuleNotFoundError: No module named 'is-number' error? Thanks   Hi, In your python environment you
port number - JavaMail
port number  i want james2.1.3 port number like microsoft telnet>open local host _______(some port number) i wnat that port number
finding divisors of a number
finding divisors of a number   write a c program to input a number and print all its divisors using while loop
finding divisors of a number
finding divisors of a number   write a c program to input a number and print all its divisors using while loop
finding divisors of a number
finding divisors of a number   write a c program to input a number and print all its divisors using while loop
Check even or odd number.
Check even or odd number.  How to check given number is even or odd... args[]) throws IOException { Sys tem.out.println("Enter the number...){ System.out.println("Number is Even"); } else
How to format number in Java?
How to format number in Java?  Hi, What is the best way to format a number in Java? How to format number in Java? Thanks   Hi, To format number in Java you can use the class java.text.NumberFormat. Here is simple
prime number - Java Beginners
prime number  this project is to determine if a phone number is a prime number. if the number is a prime number then print a message to the effect. if the number is not a prime number then print the prime factors of the number
from number to word
from number to word  i want to know weather there is any method that can be use in changing value from number to word. Example if i write ten thousand, it will automatically be written as 10000.   Java convert number
MySQL Default Port number
MySQL Default Port number  HI, What is MySQL Default Port number? Thanks   Hello, MySQL Server Default Port number is 3306. Thanks
ID number program
ID number program  hi can anyone help me with the following program. a program that can determine a person,s date of birth, age, gender and citizenship by just entering the id number. thanks in advance
Number conversion in JavaScript
Number conversion in JavaScript  How do you convert numbers between different bases in JavaScript
validate bank account number
validate bank account number  how to validate bank account number in jsp
validate bank account number
validate bank account number  how to validate bank account number in jsp

Ads