Friday, August 10, 2012

Pyramid Program 4


Pyramid Program 4
 Output
----------
1
1 2 1
1 2 4 2 1
1 2 4 8 4 2 1
1 2 4 8 16 8 4 2 1
1 2 4 8 16 32 16 8 4 2 1
1 2 4 8 16 32 64 32 16 8 4 2 1
1 2 4 8 16 32 64 128 64 32 16 8 4 2 1

Pyramid Program 4
Source code
-------------
package com.swain.cell;

public class Piramid4 {

       public static void main(String args[]){
       int i,k,j;
       for(i=1;i<=200;i= i*2){

              for(j=1; j<=i; j=j*2)
              System.out.print(j + " ");

              for(k=i/2; k>=1; k=k/2)
              System.out.print( k + " ");
              System.out.print("\n");
       }
}
}

Java Quick Program

1. Write a Code to generate Random numbers public class GenerateRandomNumbers { public static void main(String[] args) { System.out...