Tuesday, 14 June 2011

Program to Print the Fibonacci Series in java Using Array

class fibonacci
{
public static void main (String args [ ])
{
int i;
int array[] = new int[11];
array[0]= -1;
array[1]= 1;
System.out.println("The fibonacci series  is : \n");
for(i=2 ; i<array.length ; i++)
{
array[i]=array[i-2] + array[i-1];
System.out.print(array[i]+ " " );
}
}
}

OUTPUT :
The fibonacci series is :
0 1 1 2 3 5 8 13 21 



Monday, 6 June 2011

Triangle Pattern Program in java

Q.              *
               * * *
             * * * * *
           * * * * * * *

Solution :
             
class triangle
{
public static void main ( String args [ ])
{
for(int row=5 ; row>0 ; row--)
{
for(int space=0 ; space=0 ; space --)
{
System.out.print(" ");
}
for(int col=9 ; col = (row*2)+1 ; col --)
{
System.out.print("*");
}
System.out.println(" ");
}
}
}



Sunday, 5 June 2011

Pattern Programs in Java

Q.                       *
                   *  *   *
                *  *  *   *  *
                   *  *   *
                       * 


Solution :
class pattern
{
public static void main (String args[ ])
{
for(int row=5 ; row>0 ; row--)
{
for(int space=0 ; space<r ; space--)
{
System.out.print(" ");
}
for(int col=9 ; col>=(row*2)+1 ; col--)
{
System.out.print("*");
}
System.out.println( " ");
}
for(int row=2 ; row>0 ; row--)
{
for(int space=0 ; space<row ; space++)
{
System.out.print( " ");
}
for(int col=9 ; col>=(row*2)+1 ; col--)
{
System.out.print("*");
}
System.out.println(" ");
}
}
}
                                               
 AbeBooks Logo Canada
Q.                                       *
                                 *
                              *
                           *
                       *
                       
                                  
Solution :
class pattern
{
public static void main ( String args [ ] )
{
for( int row=5; row>0 ; row--)
{
for( int col=0; col < row ; col++)
{
System.out.print(" ");
}
System.out.println("*");
}
}
}