Java wrapper class Integer provides an utility function toOctalString(int) which returns an integer in octal form. However, in this post, we will also see an example on how we can convert integer to octal form mathematically without using Java API classes. If you divide a number with 8, what you get in the reminder is the last digit of its octal form. We repeat this until … [Read more...] about How to Convert an Integer to Octal in Java
Archives for April 2020
How to Reverse an Integer in Java
In this example, we will see how to reverse an integer in Java using mathematical equations, StringBuffer and StringBuilder classes. Reverse an Integer in Java using Mathematical Equations To reverse an integer mathematically, first thing what we should do is to take out the last digit as a separate integer. That is possible by dividing the number by 10. After dividing … [Read more...] about How to Reverse an Integer in Java
Quick Sort using Hoare Partition and Lomuto Partition in Java
Quick Sort is based on the divide-and-conquer strategy. It is also called a partition exchange sort. It was developed by Tony Hoare in 1959. Steps for Quick Sort: First step in Quick Sort is to choose an element called as pivot. Once the Pivot is selected, we need to reorder the elements so that:all the elements less than the Pivot are placed before Pivot, and elements … [Read more...] about Quick Sort using Hoare Partition and Lomuto Partition in Java
Bubble Sort in Java
In Bubble Sort, we always compare one array element with its adjacent element. If the first element is greater than the next element, we swap both of them. These steps will be repeated several times to push all the big numbers to the end one after one. Program: Output: … [Read more...] about Bubble Sort in Java
How to read input from User in Java
In this post, we will discuss on how to read input from User using Scanner and InputStreamReader. Scanner(System.in) To read values of known type from standard input, we can use Scanner class. When I say known types, any primitive like int, double, char or a String. Scanner provides various utility methods to read input such as nextShort(), nextFloat(), nextDouble(), … [Read more...] about How to read input from User in Java