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: Please give program for printing following pattern

***
*
**
****
**
******

corejava x 323
programming x 133
Posted On : 2016-09-06 10:59:28.0
profile rahul patil - anyforum.in rahul patil
34-30
up-rate
3
down-rate

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
Are You Satisfied : 1 Yes  0 NO
profile Rishi Kumar - anyforum.in Rishi Kumar
523184717358
Reply This Thread
up-rate
-2
down-rate

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
Are You Satisfied : 1 Yes  0 NO
profile rahul patil - anyforum.in rahul patil
34-30
Reply This Thread
up-rate
-3
down-rate
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("");
}
profile Garima Gupta - anyforum.in Garima Gupta
596  1276  20265
Posted On :2016-09-06 16:16:24.0
Leave a Comment



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