Aim:- Write an interactive program to print a diamond shape.
For example, if user enters the number 3, the diamond will be as follows:
* * *
* *
*
JAVA Code :-
import
java.lang.*;
class
pra10
{
public static void main(String args[])
{
int i,j,n;
n=Integer.parseInt(args[0]);
for(i=n;i>0;i--)
{
for(j=n;j>0;j--)
{
if(i<j)
System.out.print(" ");
else
System.out.print("* ");
}
System.out.println();
}
}
}
Output:-
No comments:
Post a Comment