Chandu yadav has Published 1163 Articles

Use reflection to create, fill, and display an array in Java

Chandu yadav

Chandu yadav

Updated on 25-Jun-2020 12:44:15

173 Views

An array is created using the java.lang.reflect.Array.newInstance() method. This method basically creates a new array with the required component type as well as length.The array is filled using the java.lang.reflect.Array.setInt() method. This method sets the required integer value at the index specified for the array.The array displayed using the for ... Read More

Sort arrays of objects in Java

Chandu yadav

Chandu yadav

Updated on 25-Jun-2020 12:39:27

405 Views

An array of objects can be sorted using the java.util.Arrays.sort() method with a single argument required i.e. the array to be sorted. A program that demonstrates this is given as follows −Example Live Demoimport java.util.Arrays; public class Demo {    public static void main(String args[]) throws Exception {       ... Read More

Modular multiplicative inverse in java

Chandu yadav

Chandu yadav

Updated on 25-Jun-2020 12:35:39

616 Views

The java.math.BigInteger.modInverse(BigInteger m) returns a BigInteger whose value is (this-1 mod m). Using this method you can calculate Modular multiplicative inverse for a given number.ProgramLive Demoimport java.math.*; public class BigIntegerDemo {    public static void main(String[] args) {       // create 3 BigInteger objects       BigInteger ... Read More

Sort Byte Array in Java

Chandu yadav

Chandu yadav

Updated on 25-Jun-2020 12:20:19

243 Views

A byte array can be sorted using the java.util.Arrays.sort() method with a single argument required i.e. the array to be sorted. A program that demonstrates this is given as follows −Example Live Demoimport java.util.Arrays; public class Demo {    public static void main(String[] args) {       byte[] arr = ... Read More

Smith Numbers in java

Chandu yadav

Chandu yadav

Updated on 25-Jun-2020 12:19:59

1K+ Views

A composite number whose sum of digits equal to the sum of the digits of its prime factors.Ex: 58 = 2 x 29 (5 + 8 = 12) (2+ 2 + 9 = 12)Programpublic class SmithNumbers {    public static boolean isPrime(int number) {       int loop;   ... Read More

Computer elapsed time of an operation in milliseconds in Java

Chandu yadav

Chandu yadav

Updated on 25-Jun-2020 12:15:48

464 Views

To compute the elapsed time of an operation in milliseconds in Java, we use the System.currentTimeMillis() method. The java.lang.System.currentTimeMillis() returns the current time in milliseconds.Declaration −The java.lang.System.currentTimeMillis() is declared as follows −public static long currentTimeMillis()The method returns time difference in milliseconds between the current time and midnight, January 1, 1970 ... Read More

Java Program to fill elements in a byte array

Chandu yadav

Chandu yadav

Updated on 25-Jun-2020 12:10:05

154 Views

Elements can be filled in a byte array using the java.util.Arrays.fill() method. This method assigns the required byte value to the byte array in Java. The two parameters required are the array name and the value that is to be stored in the array elements.A program that demonstrates this is ... Read More

Check if a large number is divisible by 11 or not in java

Chandu yadav

Chandu yadav

Updated on 25-Jun-2020 12:03:01

1K+ Views

A number is divisible by 11 if the difference between the sum of its alternative digits is divisible by 11.i.e. if (sum of odd digits) – ( sum of even digits) is 0 or divisible by 11 then the given number is divisible by 11.Programimport java.util.Scanner; public class DivisibleBy11 ... Read More

GCD and LCM of two numbers in Java

Chandu yadav

Chandu yadav

Updated on 25-Jun-2020 11:57:26

734 Views

Following is an example which computes find LCM and GCD of two given numbers.Programimport java.util.Scanner; public class LCM_GCD {    public static void lcm(int a, int b){       int max, step, lcm = 0;       if(a > b){          max = step = ... Read More

Perform Animation on border-right-width property

Chandu yadav

Chandu yadav

Updated on 25-Jun-2020 11:47:36

67 Views

To implement animation on border-right-width property with CSS, you can try to run the following codeExampleLive Demo                    div {             width: 500px;             height: 300px;         ... Read More

Advertisements