AmitDiwan has Published 10744 Articles

JavaScript - Exclude some values in average calculation

AmitDiwan

AmitDiwan

Updated on 14-Sep-2020 13:36:48

287 Views

Let’s say, we have an array of objects like this −data = [    {"Age":26, "Level":8},    {"Age":37, "Level":9},    {"Age":32, "Level":5},    {"Age":31, "Level":11},    {"Age":null, "Level":15},    {"Age":null, "Level":17},    {"Age":null, "Level":45} ];We are required to write a JavaScript function that calculates the average level for all the ... Read More

Checking for co-prime numbers - JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Sep-2020 13:33:39

437 Views

Two numbers are said to be co-primes if there exists no common prime factor amongst them (1 is not a prime number)For example −4 and 5 are co-primes 9 and 14 are co-primes 18 and 35 are co-primes 21 and 57 are not co-prime because they have 3 as the ... Read More

Finding how many time a specific letter is appearing in the sentence using for loop, break, and continue - JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Sep-2020 13:00:47

109 Views

We are required to write a JavaScript function that finds how many times a specific letter is appearing in the sentenceExampleLet’s write the code for this function −const string = 'This is just an example string for the program'; const countAppearances = (str, char) => {    let count = ... Read More

Count of N-digit Numbers having Sum of even and odd positioned digits divisible by given numbers - JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Sep-2020 12:58:39

131 Views

We are required to write a JavaScript function that takes in three numbers A, B and N, and finds the total number of N-digit numbers whose sum of digits at even positions and odd positions are divisible by A and B respectively.ExampleLet’s write the code for this function −const indexSum ... Read More

Rotating an array - JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Sep-2020 12:54:22

547 Views

Let’s say, we are required to write a JavaScript function that takes in an array and a number n and rotates the array by n elementsFor example: If the input array is −const arr = [12, 6, 43, 5, 7, 2, 5];and number n is 3, Then the output should ... Read More

Retrieving Elements from Collection in Java- EnumerationIterator

AmitDiwan

AmitDiwan

Updated on 14-Sep-2020 09:41:53

219 Views

EnumerationIterator doesn’t have the option of eliminating elements from the collection, whereas an iterator has this facility. An additional disadvantage of using EnumerationIterator is that the name of methods associated with EnumerationIterator is difficult to remember.ExampleFollowing is an example − Live Demoimport java.util.Vector; import java.util.Enumeration; public class Demo {    public ... Read More

Retrieving Elements from Collection in Java- ListIterator

AmitDiwan

AmitDiwan

Updated on 14-Sep-2020 09:39:05

234 Views

Following is an example to retrieve elements from Collection in Java-ListIterator −Example Live Demoimport java. util.* ; public class Demo {    public static void main(String args[]) {       Vector my_vect = new Vector();       my_vect.add(56);       my_vect.add(78);       my_vect.add(98);       ... Read More

Retrieving Elements from Collection in Java- Iterator

AmitDiwan

AmitDiwan

Updated on 14-Sep-2020 09:36:16

360 Views

Following is an example to retrieve elements −Example Live Demoimport java.util.*; public class Demo {    public static void main(String args[]) {       HashSet my_hs = new HashSet() ;       my_hs.add("Joe");       my_hs.add ("Rob");       Iterator my_it = my_hs.iterator();       System.out.println("The ... Read More

Retrieving Elements from Collection in Java- For-each loop

AmitDiwan

AmitDiwan

Updated on 14-Sep-2020 09:34:04

320 Views

The ‘for-each’ loop is used to iterate over a set of elements that is stored in a data structure.Syntaxfor (element e: collection) {    System.out.println(e); }ExampleFollowing is an example − Live Demopublic class Demo {    public static void main(String[] args) {       int[] my_vals = {5, 67, 89, ... Read More

Reflection Array Class in Java

AmitDiwan

AmitDiwan

Updated on 14-Sep-2020 09:26:40

578 Views

The array class present in java.lang.reflect package belong to the Java reflection class. The Java Reflection class provides static methods, and these methods can be used to create and access Java arrays in a dynamic manner. This class is final, and this means it can’t be changed or even instantiated. ... Read More

Advertisements