Tuesday, June 25, 2013

How to add two numbers,each number has more than 1 lakh digits

                                             Today i posted about "How to add two numbers,each number has more than 1 lakhs digits?".If i ask how to add two numbers everyone said, by using '+' operators through primitive type variables.In any programming language,each primitive type has their limits.For example in java, int primitive type range is -2,147,483,648 to 2,147,483,647 and int maximum range is 10 digit number. No such type of primitives to store more than 100000 digits in any language. By using primitives we cannot solve this problem  so we use String type variables.
                                For solving this problem take two String variables, take input from user and store into this variables.After convert String variables into character arrays by using String class method toCharArray() method.
For Example:
  String str="1234567890";
 char ch[]=(int)str.toCharArray();
for(int index=0;index<ch.length;index++){
 System.out.println(ch[index]);
}

output is 1 2 3 4 5 6 7 8 9 0

After converting into character array,take first array of last index with second array of last index.

For more clarity see below program:
Click on for Addition.java



Wednesday, June 19, 2013

Floyd's Triangle

Write a program to print the Floyd's Triangle?  

1
2   3
4   5   6
7   8   9   10
11 12 13 14  15

import java.util.*;
class FloydTriangle
{
 public static void main(String[] args)
 {
     Scanner scannerInput=new Scanner(System.in);
     System.out.println("Enter how rows you want");
     int rows=scannerInput.nextInt();
     int num=1;
     for(int index=0;index<rows;index++)
     {
         int repeat=index;
         while(repeat>=0)
         {
             System.out.print(num+" ");
             num++;
             repeat--;
         }
         System.out.println("\n");
     }
 
}


Enter how rows you want 5
1 

2 3 

4 5 6 

7 8 9 10 

11 12 13 14 15 

                          

Saturday, June 1, 2013

Tribonacci Series

                                                 Tribonacci Series is like a Fibonacci Series, but some difference between these two.
                          The Fibonacci sequence is introduced by Leonardo  Pisano,an Italian Mathematician.The Fibonacci sequence is a set of numbers that starts with  a Zero or a one,followed by one and proceds based on the rule that each number  is equal to sum of the preceding two numbers.The Fibonacci sequence is denoted by F(n) ,where n is the first term in the sequence.For n=0,where the first two terms are obtained as 0 and 1.The series is
F(0)=0,1,1,2,3,5,8,.................


                                  The Tribonacci Sequence is a set of numbers that start with a Zero or a one,followed by two one's and proceds based on the rule  that each number is equal to sum of the preceding three numbers.The Tribonacci Sequence is denoted by F(n),where n is the first term in the sequence.For n=1,where the first three terms are 0,1 and 1.
The series is
F(1)=1,1,1,3,5,9,17,31,......





Binary Pyramid Program

Write a Java program to print the following Binary Pyramid?

                                              1 
                                            010
                                          10101
                                        0101010


Output:

Enter range of Binary Pyramid: 5

                                                 
                                            010
                                          10101
                                        0101010