Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Programming Articles
Page 1309 of 2547
Java Program to check if count of divisors is even or odd
To check if the count of divisors is even or odd, the Java code is as follows −Exampleimport java.io.*; import java.math.*; public class Demo{ static void divisor_count(int n_val){ int root_val = (int)(Math.sqrt(n_val)); if (root_val * root_val == n_val){ System.out.println("The number of divisors is an odd number"); }else{ System.out.println("The number of divisors is an even number"); } } public static void main(String args[]) throws IOException{ divisor_count(25); } }OutputThe number of divisors is an odd ...
Read MoreProduct of first N factorials in C++
Given a number N, the task is to find the product of first N factorials modulo by 1000000007. . Factorial implies when we find the product of all the numbers below that number including that number and is denoted by ! (Exclamation sign), For example − 4! = 4x3x2x1 = 24.So, we have to find a product of n factorials and modulo by 1000000007..Constraint 1 ≤ N ≤ 1e6.Input n = 9Output 27Explanation 1! * 2! * 3! * 4! * 5! * 6! * 7! * 8! * 9! Mod (1e9 + 7) = 27Input n = 3Output 12Explanation 1! * 2! * 3! mod (1e9 ...
Read MoreJava Program to check whether it is possible to make a divisible by 3 number using all digits in an array
To check whether it is possible to make a divisible by 3 number using all digits in an array, the Java code is as follows −Exampleimport java.io.*; import java.util.*; public class Demo{ public static boolean division_possible(int my_arr[], int n_val){ int rem = 0; for (int i = 0; i < n_val; i++) rem = (rem + my_arr[i]) % 3; return (rem == 0); } public static void main(String[] args){ int my_arr[] = { 66, 90, 87, 33, 123}; ...
Read MoreProduct of factors of number in C++
Given a number n we have to find its all factors and find the product of those factors and return the result, i.e, the product of factors of a number. Factors of a number are those numbers which can divide the number completely including 1. Like factors of 6 are − 1, 2, 3, 6.Now according to the task we have to find the product all the factors of the number.Input − n = 18Output − 5832Explanation − 1 * 2 * 3 * 6 * 9 * 18 = 5832Input − n = 9Output − 27Explanation − 1 * 3 * 9 = 27Approach used below is as follows to solve the problem −Take the input num .Loop from i = 1 till i*i
Read MoreJava Program to Convert Iterator to Spliterator
To convert Iterator to Spliterator, the Java code is as follows −Exampleimport java.util.*; public class Demo{ public static Spliterator getspiliter(Iterator iterator){ return Spliterators.spliteratorUnknownSize(iterator, 0); } public static void main(String[] args){ Iterator my_iter = Arrays.asList(56, 78, 99, 32, 100, 234).iterator(); Spliterator my_spliter = getspiliter(my_iter); System.out.println("The values in the spliterator are : "); my_spliter.forEachRemaining(System.out::println); } }OutputThe values in the spliterator are : 56 78 99 32 100 234A class named Demo contains a function named ‘getspiliter’ that returns a spliterator. In the ...
Read MoreJava program to count the characters in each word in a given sentence
To count the characters in each word in a given sentence, the Java code is as follows −Exampleimport java.util.*; public class Demo{ static final int max_chars = 256; static void char_occurence(String my_str){ int count[] = new int[max_chars]; int str_len = my_str.length(); for (int i = 0; i < str_len; i++) count[my_str.charAt(i)]++; char ch[] = new char[my_str.length()]; for (int i = 0; i < str_len; i++){ ch[i] = my_str.charAt(i); int find = 0; for (int j = 0; j
Read MoreJava Program to Count trailing zeroes in factorial of a number
To count trailing zeroes in factorial of a number, the Java code is as follows −Exampleimport java.io.*; public class Demo{ static int trailing_zero(int num){ int count = 0; for (int i = 5; num / i >= 1; i *= 5){ count += num / i; } return count; } public static void main (String[] args){ int num = 1000000; System.out.println("The number of trailing zeroes in " + num +" factorial is " + ...
Read MoreJava program to expand a String if range is given?
To expand a String if range is given, the Java code is as follows −Examplepublic class Demo { public static void expand_range(String word) { StringBuilder my_sb = new StringBuilder(); String[] str_arr = word.split(", "); for (int i = 0; i < str_arr.length; i++){ String[] split_str = str_arr[i].split("-"); if (split_str.length == 2){ int low = Integer.parseInt(split_str[0]); int high = Integer.parseInt(split_str[split_str.length - 1]); while (low
Read MoreJava Program to find reminder of array multiplication divided by n
To find reminder of array multiplication divided by n, the Java code is as follows −Exampleimport java.util.*; import java.lang.*; public class Demo{ public static int remainder(int my_arr[], int arr_len, int val){ int mul_val = 1; for (int i = 0; i < arr_len; i++) mul_val = (mul_val * (my_arr[i] % val)) % val; return mul_val % val; } public static void main(String argc[]){ int[] my_arr = new int []{ 35, 100, 69, 99, 27, 88, 12, 25 }; ...
Read MoreJava Program to Find the closest pair from two sorted arrays
To find the closest pair from two sorted array, the Java code is as follows −Examplepublic class Demo { void closest_pair(int my_arr_1[], int my_arr_2[], int arr_1_len, int arr_2_len, int sum){ int diff = Integer.MAX_VALUE; int result_l = 0, result_r = 0; int l = 0, r = arr_2_len-1; while (l=0){ if (Math.abs(my_arr_1[l] + my_arr_2[r] - sum) < diff){ result_l = l; result_r = r; diff ...
Read More