AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
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 ?.



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 352
programming x 168
Posted On : 2014-08-17 00:31:17.0
profile Saksham Kumar - anyforum.in Saksham Kumar
72933916624
up-rate
3
down-rate

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
profile Rishi Kumar - anyforum.in Rishi Kumar
523188222140
Reply This Thread
up-rate
5
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in