Home >Java >javaTutorial >Java program to get the number of elements with odd factors in a given range
To get the number of elements with odd factors in a given range, the Java code is as follows -
import java.io.*; import java.util.*; import java.lang.*; public class Demo{ public static int square_count(int low_range, int high_range){ return (int)Math.pow((double)high_range,0.5) - (int)Math.pow((double)low_range-1,0.5); } public static void main (String[] args){ int low_range = 55, high_range = 1000; System.out.print("The number of values with odd factors between a given range of numbers is : " + square_count(low_range, high_range)); } }
The number of values with odd factors between a given range of numbers is : 24
The class named Demo contains a function named "square_count". The function is defined by passing two integer values as parameters. It returns the number of elements with odd factors in the given range. This is done using the mathematical function "pow". In the main function, the lower and upper range values are defined and the function "square_count" is called with the lower and upper range values. Related messages are displayed on the console.
The above is the detailed content of Java program to get the number of elements with odd factors in a given range. For more information, please follow other related articles on the PHP Chinese website!