Search This Blog

Sunday, 13 October 2013

Print Pyramid in java

import java.io.*;
class printPyramidDemo
{
public static void main(String arg[]) throws IOException
     {
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the height of pyramid ");
 String s=br.readLine();
int a=Integer.parseInt(s);
 for(int i=0; i<=a; i++)
         {
            for(int k=a; k>=i; k--)
               {
                System.out.print(" ");
                }
           int c=(2*i)-1;
           for(int j=1; j<=c; j++)
               {
                  System.out.print("*");
               }
    System.out.print("\n");
          }
     }
}
output

Addtion Of two Numbers in java

import java.io.*;
class addition
{
    public static void main(String args[]) throws IOException
        {
             float no3;            
             DataInputStream in=new DataInputStream(System.in);
             System.out.println("enter  1st float value for addition:");
             float no1=Float.valueOf(in.readLine()).floatValue();
              System.out.println("enter  2nd float value for addition:");
             float no2=Float.valueOf(in.readLine()).floatValue();
                no3=no1+no2;           
              System.out.println("value of addition is:"+no3);
         }
       

ouput   

Print Numbers By for loop

import java.util.*;
class forloop
{
    public static void main(String args[])
    {
       Scanner in=new Scanner(System.in);
       int n;
       System.out.println("Enter the value:");
       n=in.nextInt();
       System.out.println();
       for(int i=0;i<n;i++)
       {
          System.out.print(i);
        }
    }
}


output 

 

Popular Posts