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

                                                  1 
                                            010
                                          10101
                                        0101010

Friday, May 24, 2013

Why new watches show 10:10 behind any reason is there

                                          When we  go to watch or clock shop,where all watches are showing 10:10.Can you any movement think why clocks are showing this time.Yes,for showing this time on watches behind one interesting reason is there.
                                         The hours hand at 10 and minutes hand at 2.The reason for this,read below statements
1. When we are enter into the watch shop,every one think about price of watch, brand, Warranty and other details.But never think why watches showing 10:10.

2. Behind it there is one beautiful and interesting reason is there.

3. Clock and watch makers to sale there watches in market,they need one logo for selling  their goods.They want logo to be simple and meaningful.

4. Then they trying keep watch hands on different number then observe that.10:10 place showing Smiley face.It is possible only on 10:10,not possible on any other numbers.

5. Keep this logo on watches sales their goods different way in market.But this is very interesting and hiding symbol.


Watch showing 10:10







Smiley Face

















Tuesday, May 21, 2013

Sort two input arrays in Ascending order and find the median of elements without using any predefined methods of Java

                                 Sorting of array is easy to sort the array in descending order.To sort the array elements  java gives the predefined methods.Sort two input array elements in ascending order without using any predefined methods of Java,this question asked in Cap-Gemini Coding Challenge Test. This program is some what difficult but i have a easy way to write this program.

 Actually Cap-Gemini given this as below:

In Bangalore, Cap-Gemini has departments.Department A has m employees with empNumber and Department B has n employees with empNumber. Combine this two departments into single department and sort the empNumbers  in ascending order. And find the median of employ.
Conditions:
All employees are even number then 
  pos1=(m+n)/2
pos2=(m+n)/2+1
avg=(pos1+pos2)/2
Odd numbers:
 pos=(m+n)/2

   
 Example:
 Input:
           Employ Numbers of Department A={12,6,5,2,3}
           Employ Numbers of Department B={9,5,13,10,1,11}

Output:
           Employees of Department of A following token numbers:12  6 5 2 3
         
           Employees of Department of B following token numbers: 9 5 13 10 1 11
         
           Total Employees=11
     
           Median=9
          
For program click on below link:


Sunday, May 19, 2013

Write a program to sort the integer number without using any predefined method of java

                     For this program we cannot use any predefined method of java to write this program.First we under stand question clearly. Directly not possible to sort integer number but we can sort integer array.

            In this program, first i take input integer value as String.Convert string value to character array and sort character array. Assign character array to String.Now convert String to integer.

            This is the process to sort integer value without using any predefined methods of java.

If you want see the click on below link: