Number
- 30 March
java random number between 1 and 10
We have already seen random number generator in java.In this post, we will address specific query on how to generate random number between 1 to 10. Using random.nextInt() to generate random number between 1 and 10 We can simply use Random class’s nextInt() method to achieve this. As the documentation says, this method call returns "a […]
- 01 August
Count Factorial Trailing Zeroes in java
In this tutorial, we will see how to count trailing zeros in factorial of a number in java. Problem Count number of zeros in factorial of number in java. For example: Factorial of 6 is 720, so a number of trailing zeros is 1. Factorial of 14 is 87 178 291 200, so a number […]
- 20 January
Java program to print Fibonacci Series
In this tutorial, we will print fibonacci series. According to wikipedia: In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and characterized by the fact that every number after the first two is the sum of the two preceding ones:[1][2] 0,1,1,2,3,5,8,13,21,34,55,89,144.. Here is simple program to print […]
- 19 January
Java program for sum of digits of number
In this post, we will see how to find sum of digits of number in java. You can find unit’s place digit by number%10, add it to the total and divide the number by 10 to remove the unit’s place. [crayon-6767b8e2e20b1276515406/] Output: Enter a Number : 5385 Sum of digits of number 5385 is 21 […]
- 19 January
Java program to calculate average marks
In this post, we will see simple java program to find average and percentage marks. We have taken average and percentage of five subject marks below. [crayon-6767b8e2e214a069013504/] Output: Enter marks for 5 Subjects : 91 57 83 69 74 Average Marks = 74.8 Percentage = 74.8% That’s all about Java program to calculate average and […]
- 18 January
Even odd program in java
In this post,we will see how to check if number is even odd. It is one of the basic programs of Java programming language. [crayon-6767b8e2e21d8863271978/] Output: Enter a Number : 22 22 is an Even Number That’s all about Even odd program in java.
- 18 January
Java Program to add two numbers
In this post, we will see how to add two numbers in java. This is the most basic program of java programming language. [crayon-6767b8e2e2252762272210/] Output: Enter two numbers : 5 7 Sum of two numbers is 12 If you notice, we have use Scanner to take input from user.
- 24 December
Reverse number in java
In this post, we will see how to reverse a number in java. Here is simple program to reverse a number. [crayon-6767b8e2e22cc410559539/] Output: Enter a Number : 4567 Reverse of the number : 7654 Let’s just observe values of variables at the end of each iteration. Iteration 0: number = 4567,remainder = 0, reversedNumber = […]
- 10 November
Java Format number as currency
In this post, we are going to see how to format currency in java. We can format number into Currency by using NumberFormat class.We need to call NumberFormat.getInstance() to get NumberFormat object by passing specified locale. For example: Let’s say you want a Format object for UK Locale or US Locale. You can simply use below […]