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: Please give program for printing following pattern
***
*
**
****
**
******
corejava x 353
programming x 169
Posted On :
2016-09-06 10:59:28.0
rahul patil
42
-3
0
3
Answers
public class Pattern {
public static void main(String[] args) {
int count=3;
for(int i=1;i<=6;i++){
for(int j=1;j<=count;j++){
System.out.print("*");
}
if((count==1 || count==2) && i<=3){
count=2*count;
}
if(count==3){
count=1;
}
if(count==4 && i==4){
count=count/2;
}
if(count==2 && i==5){
count=count*3;
}
System.out.println("");
}
}
}
Posted On :
2016-09-06 14:07:40
Satisfied :
1 Yes
0 No
Rishi Kumar
523
1882
49150
Reply This Thread
-2
can we do like this ?
int b=3,a=1;
for (int i = 1; i < 4; i++)
{
for (int j = 1; j <= b; j++) {
System.out.print("*");
}
System.out.println();
for (int j1 = 1; j1 <= a; j1++)
{
System.out.print("*");
}
System.out.println();
int c=0;
if(b>a)
c=b-a;
else
c=a-b;
a=a+b;
b=c;
}
Posted On :
2016-09-06 15:44:18
Satisfied :
1 Yes
0 No
rahul patil
42
-3
0
Reply This Thread
-3
Comments
We can solve one problem by multiple ways, but what matters is how much resource we consume. I want to make some changes in first answer posted by Raj.
int count=3;
for(int i=1;i<=6;i++){
for(int j=1;j<=count;j++){
System.out.print("*");
}
if(count==3){
count=1;
}
else if((count==1 || count==2) && i<=3){
count=2*count;
}
else if(count==4 && i==4){
count=count/2;
}
else if(count==2 && i==5){
count=count*3;
}
System.out.println("");
}
Garima Gupta
596
1295
58962
Posted On :
2016-09-06 16:16:24.0
Leave a Comment
Post Answer
Please Login First to Post Answer:
Login
Answer:
anyforum.in