AF
Home
Tag
Submit Notes
Ask Anything
Login
Subscribe Us
A
ny
F
orum
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.
Follow @anyforumin
corejava-programming: write a program to print triangle pattern with two characters?
Please give me java source code to print the following pattern.
*0*0*0
*0*0*
*0*0
*0*
*0
*
corejava x 353
programming x 169
Posted On :
2014-08-17 00:31:17.0
Saksham Kumar
734
339
39909
3
Answers
As you are seeing in above pattern, It requires two for loops one in another. and if you notice that in second for loop if even no. lies it is printing * otherwise 0. So following is the complete source code to print this pattern.
TrianglePattern.java:
----------------------------------------------
class TrianglePattern{
public static void main(String args[]){
for(int i=1;i<=6;i++){
for(int j=6;j>=i;j--)
{
if(j%2==0){System.out.print("*");}
else{System.out.print(0);}
}
System.out.println();
}
}
}
Posted On :
2014-08-17 00:42:55
Satisfied :
1 Yes
0 No
Rishi Kumar
523
1882
50047
Reply This Thread
5
Post Answer
Please Login First to Post Answer:
Login
Answer:
anyforum.in