Ore Number in Java

Ore number is a positive integer whose divisors have a harmonic value as an integer. Ore number is also known as harmonic divisor number. For example, 6 has four factors: 1, 2, 3 and 6. Harmonic mean of the factors is: 4 / (1 + 1 / 2 + 1 / 3 + 1 / 6) = 2 The harmonic mean of the factors of 6 is 2, which is an integer. So, 6 is an Ore number or harmonic divisor number. Write a program in Java to input an integer and check whether it is an Ore Number or not. 
import java.io.*;
 class Ore
{
 public static void main(String args[])throws IOException
{
 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 System.out.print("Enter the number: "); 
 int num = Integer.parseInt(br.readLine()); 
 int f = 0;
 double mean = 0.0;
 for(int i = 1; i <= num; i++)
{
 if(num % i == 0)
{
 f++; mean += 1.0 / i;
 }
 }
 mean = f / mean; 
 if(mean == (int)mean) 
 System.out.println(num + " is an Ore Number.");
 else
 System.out.println(num + " is NOT an Ore Number.");
 }
 }

No comments:

Post a Comment

any problem in any program comment:-

Second largest number in java using ternary operator

 //Largest second number using ternary operator public class Main { public static void main(String[] args) { int a=5,b=6,c=7; int ...