March 6 2017

Java program convert decimal to binary

Java program convert decimal to binary

Decimal number system is a base 10 number system using digits for 0 to 9 whereas binary number system is base 2 and uses 0 and 1.

Algorithm to convert Decimal to Binary number

  1. Divide the decimal number by 2 and store the remainder
  2. Store the quotient back to the input number variable
  3. Repeat step 1 and 2 till quotient becomes zero.
  4. Binary number will be the remainders in above process in reverse order

Example             Continue reading

March 2 2015

Leap year program in java

Leap year program in java

A normal year has 365 days.
A leap year has 366 days (the extra day is the 29th of February)

example : 2012, 2016, 2020, 2024 …

Algorithm

1. Take the year from the user (year)
2. If the year is divisible by 400 it is a leap year
3. If the year is divisible by 4 and not divisible by 100 it is a leap year
4. If step 2 or step 3 conditions are not satisfied,It is a not leap year Continue reading

March 2 2015

Pascal triangle program in java

Pascal triangle program in java

Pascal’s triangle is a triangular array of the binomial coefficients.It is named after Blaise Pascal, a famous French Mathematician and Philosopher)

As show in figure,the triangle will start with 1 at the top and placing the numbers below it in the traiangular format.Except the edges(1’s), each number is the sum of two numbers above it.

Algorithm

pascal triangle program in java

1.Take ‘number of rows’ from the user(n)
2.Iterate from 0 to n(i)
3.Add spaces for every iteration from n-1 spaces to 0 spaces(j)
4.Iterate from 0 to i(k)
5. Print the values using (number * (i – k) / (k + 1)) Continue reading

February 24 2015

Automorphic number java program

Automorphic number java program

In mathematics an automorphic number is a number whose square ends in the same digits as the number itself.

For example,

52 = 2562 = 36 ,252=625 , 762 = 5776

The sequence of automorphic numbers begins 1, 5, 6, 25, 76, 376, 625, 9376…

Algorithm

  • Take the input from the user (number)
  • Calculate number of digits in the number(digits)
  • Calculate square of the number(numberSquare)
  • Calculate the reminder of number divided by the 10 to power of digits(lastDigits)
  • If number is equal to last digits of the number,It is automorphic
  • Else it is not automorphic

Continue reading

February 12 2015

Palindrome number program in java

Palindrome number program in java

A palindromic number is a number that remains the same when its digits are reversed.Like 13231 for example is palindrome number whereas 2344 is not.

Algorithm

Step 1: Take the number from user and store entered number in number and tempNumber

Step 2: Repeat steps 3-5 until number != 0

Step 3: Divide number by 10 and determine remainder

reminder = number % 10;

Continue reading