In order to generate random bytes in Java, we use the nextBytes() method. The java.util.Random.nextBytes() method generates random bytes and provides it to the user defined byte array.Declaration − The java.util.Random.nextBytes() method is declared as follows −public void nextBytes(byte[] bytes)where bytes is the byte array.Let us see a program to generate random bytes in Java −Example Live Demoimport java.util.Random; public class Example { public static void main(String[] args) { Random rd = new Random(); byte[] arr = new byte[7]; rd.nextBytes(arr); System.out.println(arr); } }Output[B@15db9742Note − The output might ... Read More
In order to roll a six sided die 6000 times in Java, we need to the nextInt() statement with decision making statements.The nextInt() method returns the next random integer value from this random number generator sequence.Declaration − The java.util.Random.nextInt() method is declared as follows −public int nextInt()Let us see a program to roll a six sided die 6000 times −Example Live Demoimport java.util.Random; public class Example { public static void main(String args[]) { Random rd = new Random(); // random number generator int freq[] = new int[6]; // creating an array to compute frequency ... Read More
The voice-range property in CSS is used to set the range of the speaking voice. This is the pitch range.The following is the syntax:voice-range: [[x-low | low | medium | high | x-high]]Above, set the range of pitch i.e. low, medium, high, etc.The following is an example of the voice-range property:p { voice-range: 90Hz; }
In order to convert a Queue to a List in Java, we can create an LinkedList and pass the Queue as an argument in the parameterized constructor of an ArrayList. This can be done as follows −Queue q = new LinkedList(); List l = new ArrayList(q);The quickest way is used to LinkedList in the first place which can be used both as a List and a Queue. This can be done as follows −Queue q = new LinkedList(); List l = (List) q;Let us see a program to convert a queue to a list −Example Live Demoimport java.util.LinkedList; import java.util.List; import ... Read More
To check if a given String contains only unicode letters, digits or space, we use the isLetterOrDigit() and charAt() methods with decision making statements.The isLetterOrDigit(char ch) method determines whether the specific character (Unicode ch) is either a letter or a digit. It returns a boolean value, either true or false.Declaration −The java.lang.Character.isLetter() method is declared as follows −public static boolean isLetter(char ch)The charAt() method returns a character value at a given index. It belongs to the String class in Java. The index must be between 0 to length()-1.Declaration −The java.lang.String.charAt() method is declared as follows −public char charAt(int index)Let us ... Read More
To implement animation on margin-top property with CSS, you can try to run the following codeExampleLive Demo div { background-color: orange; animation: myanim 4s infinite; color: white; } @keyframes myanim { 30% { margin-top: 30px; } } Heading One This is demo text.
To implement animation on min-width property with CSS, you can try to run the following codeExampleLive Demo div { overflow: auto; width: 50%; background-color: blue; color: white; border: 1px solid black; animation: myanim 3s infinite; } @keyframes myanim { ... Read More
Binary search on a double array can be implemented by using the methodjava.util.Arrays.binarySearch(). This method returns the index of the required double element if it is available in the array, otherwise it returns (-(insertion point) - 1) where the insertion point is the position at which the element would be inserted into the array.A program that demonstrates this is given as follows −Example Live Demoimport java.util.Arrays; public class Demo { public static void main(String[] args) { double d_arr[] = { 5.2, 7.5, 9.7, 1.8, 4.0 }; Arrays.sort(d_arr); System.out.print("The sorted array is: ... Read More
To implement animation on the transform-origin property with CSS, you can try to run the following codeExampleLive Demo #demo1 { position: relative; height: 300px; width: 400px; border: 2px solid black; margin: 100px; padding: 5px; } #demo2 { padding: 30px; position: absolute; border: 1px solid black; background-color: orange; transform: rotate(45deg); transform-origin: 30% 10%; animation: mymove 3s infinite; } @keyframes mymove { 30% { transform-origin: 0 0 0; } } CSS transform-origin property Demo
The CSS rest-after property is useful for speech media to set pause before an element.Let us see an example of rest-before speech media propertyh1 { rest-before: 15ms; }The time sets the pause in milliseconds.