Author: Arpit Mandliya
- 06 October
Implement distance formula in java
In this post, we will see how to implement distance formula between two points in java. Formula to find distance between two points ( x1, y1) and (x2 , y2) is d= sqrt( (x2-x1)^2+ (y2 – y1)^2) Here is simple program to calculate distance between two points in java. [crayon-67889e9c648e8487035590/] Here we have used math.sqrt […]
- 06 October
Convert decimal to binary in java
In this post, we will see how to convert decimal to binary in java. There are lot of ways to convert decimal to binary in java.Let’s explore them one by one. Using Integer.toBinaryString() method You can simply use inbuilt Integer.toBinaryString() method to convert a decimal [crayon-67889e9c64ba3235551034/] Output: Binary representation of 12 : 1100 Binary representation […]
- 05 October
Calculate total surface area of Cylinder in java
In this post, we will see how to calculate total surface area of Cylinder in java. Formula of calculating total surface area of Cylinder is: Surface area of Cylinder = 2 *Î * r * r + 2 *Î * r * h Where r is radius of cylinder and h is height of cylinder […]
- 05 October
Calculate total surface area of Hemisphere in java
In this post, we will see how to calculate total surface area of Hemisphere in java. Hemisphere is exactly half of sphere. There can be many practical examples of Hemisphere. You can divide earth into two hemisphere i.e. Northen Hemisphere and Southern Hemisphere. Formula of calculating total surface area of Hemisphere is: surface area of […]
- 05 October
Get Random Number between 0 and 1 in Java
In this post, we will see how to get random number between 0 to 1 in java. We have already seen random number generator in java. Get Random Number between 0 and 1 in Java We can simply use Math.random() method to get random number between 0 to 1. Math.random method returns double value between […]
- 05 October
Print prime numbers from 1 to 100 in java
In this program, we will print prime numbers from 1 to 100 in java. A prime number is a number which has only two divisors 1 and itself. To check if the number is prime or not, we need to see if it has any other factors other than 1 or itself. If it has, […]
- 05 October
java.lang.NumberFormatException
In this post, we will see about Java.lang.NumberFormatException. java.lang.NumberFormatException occurs where you try to convert any non-numeric String to Number such as Integer, Double, Float or Long. This exception generally occurs when you get input from user in the form of String. This is not Java developer‘s fault and mostly data error. In this scenario, […]
- 23 September
JUnit assertFalse example
Junit 5’s org.junit.jupiter.Assertions class provides different static assertions method to write test cases. Please note that you need to use JUnit’s org.junit.Assert class in case of JUnit 4 or JUnit 3 to assert using assertFalse method. Assertions.AssertFalse() checks if supplied boolean condition is false. In case, condition is true, it will through AssertError. public static […]
- 19 September
JUnit assertTrue example
Junit 5’s org.junit.jupiter.Assertions class provides different static assertions method to write test cases. Please note that you need to use JUnit’s org.junit.Assert class in case of JUnit 4 or JUnit 3 to assert using assertTrue method. Assertions.assertTrue() checks if supplied boolean condition is true. In case, condition is false, it will through AssertError. public static […]