Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Wednesday, August 15, 2012

CJ-17: Program to print a pattern

Type the programs in NOTEPAD or DOS prompt itself, for Consol Application.
Type in NETBEANS or ECLIPSE for Window Application.
Here after , I am just typing the programs only..to know more about it , refer

Introduction to JAVA 

before doing any JAVA Programs.
***********************************************************************************************
Program to print a pattern as shown below :
*
* *
* * *
* * * * 
* * * * * 
***********************************************************************************************
import java.io.*;
public class nestedloop 
{
    public static void main(String args[])
    {
        int i,j;
        for(i=0;i<5;i++)
        {
            for(j=0;j<i;j++)
            {
                System.out.print("*");
                System.out.print("  ");
            }
            System.out.println("");
        }
    }  
}
=========================================================================
Output : 
*
* *
* * *
* * * * 
* * * * * 


No comments: