Core java
14 DecemberJava String to BigInteger
In this tutorial, we will see how to convert String to BigInteger in java. It is simple to convert String to BigInteger in java.We can simply use BigInteger’s constructor to convert String to BigInteger. BigInteger(String val) Above constructor convert String representation of BigInteger to BigInteger Let’s see this with the help of example: package org.arpit.java2blog; […]
14 DecemberBigDecimal divide
In this tutorial we will see about BigDecimal‘s divide method. BigDecimal’s divide method is used to divide one BigDecimal by another. You can specify scale and rounding mode to get the output according to your need. There are 6 overloaded versions of divide method. Syntax BigDecimal divide ( BigDecimal divisor) BigDecimal divide ( BigDecimal divisor, […]
14 DecemberBigDecimal round
In this tutorial, we will see about BigDecimal‘s round method. BigDecimal’s round method is used to round the BigDecimal based on MathContext setting. Syntax public BigDecimal round ( MathContext mc) Return type returns BigDecimal rounded with MathContext setting BigDecimal round example Let’s understand BigDecimal method with the help of example import java.math.*; package org.arpit.java2blog; import […]
13 DecemberJava Random nextDouble
In this tutorial, we will see Java Random nextDouble method.It is used to generate random double. It returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator’s sequence. Syntax random.nextDouble() Here random is object of the java.util.Random class. Return returns random double. Example Let’s understand with the help […]
13 DecemberJava Random nextInt
In this tutorial, we will see Java Random nextInt method.It is used to generate random integer. There are two overloaded versions for Random nextInt method. nextInt() Syntax random.nextInt() Here random is object of the java.util.Random class. Return returns random integer. Example Let’s see a very simple example: package org.arpit.java2blog; import java.util.Random; public class RandomNextIntMain { […]
13 DecemberJava – generate random String
In this tutorial, we will see how to generate random String in java. There are many ways to generate random String.Let’s explore some of ways to generate random String. Using simple java code with Random You can use SecureRandom class to generate random String for you. Let’s understand with the help of example. package org.arpit.java2blog; […]
13 DecemberRandom number generator in java
In this tutorial, we will see about random number generators.You might have requirement where you want to generate random numbers to perform some operation. For example: Let’s say you are creating a game which uses dice for each player’s turn. You can put logic to generate random number whenever the player uses dice. There are […]
17 NovemberJava program to print floyd’s triangle
In this post, we will see how to print Floyd’s triangle in java. Problem You need to print Floyd’s triangle as below for n=5. Floyd’s triangle **************** 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Floyd’s triangle in java Let’s create class "FloydTriangleMainExample.java" as below package org.arpit.java2blog; /* […]
17 NovemberPrint Numbers Using Multiple Threads in Java
In this post, we will see how to print numbers using multiple threads in java.It is similar to printing odd-even numbers using two threads in java. Problem You are given 3 threads. You need to print sequence using these 3 threads.You need to print in natural order up to MAX. For example: Let’s say you […]