DWQA Ask QuestionCategory: JavaJava_Q:Write a Java program by using two for loops to produce the output
admin Staff asked 7 years ago

Write a Java program by using two for loops to produce the output shown below:

*******

******

*****

****

***

**

*

Ankita Rawat replied 7 years ago

public class Structure {

@BeforeClass
public static void setUpBeforeClass() throws Exception {
}

@AfterClass
public static void tearDownAfterClass() throws Exception {
}

@Before
public void setUp() throws Exception {
}

@After
public void tearDown() throws Exception {
}

@Test
public void test() {

}

@Test
public void Structure() {

int number=7;
for(int i = 1; i = i; j–) {
System.out.print(“*”);
}
System.out.println();
}

}
}

2 Answers
Kulkarni Arundhati answered 7 years ago
Start your code here
public class Twofor {

public static void main(String[] args) {
// TODO Auto-generated method stub
int i,j;
char n;
String ch = "programe";


for(i=0;i<ch.length();i++){
for(j=0;j<=i;j++){
n=ch.charAt(j);
System.out.print(n);
}
System.out.println();
}

}

}
Kulkarni Arundhati answered 7 years ago

 

Start your code here
//this programe gives desire output
public class Pattern1 {

public static void main(String[] args) {
// TODO Auto-generated method stub
int i,j;
for(i=0; i<=6;i++){
for(j=6; j>=i;j--){
System.out.print("*");
}
System.out.println();
}
}

}