Nested while loop
843789Mar 9 2010 — edited Mar 11 2010Hi all, first poster here! I'm a Bio major taking a few programming classes for enrichment. Ok enough about me...
I'm stumped on this assignment. It's the last part of a series, the rest were easy enough, but I can't figure this last one out. What I need is an output of x number of right triangles using nested while loops, from the smallest one (height of 1) to the largest (height of 'x'). Can someone give me an example of this?
*
*
**
*
**
***
*
**
***
****
*
**
***
****
*****
I figured out how to make a single right triangle:
import java.util.Scanner;
public class wtfman
{
public static void main(String[] args)
{
Scanner kb = new Scanner(System.in);
int a, b, c, x, row_count, col_count, tri_count;
x = kb.nextInt();
row_count = 1;
while( row_count <= x ) // row_count = 1, 2, 3, 4, 5
{
col_count = 1;
while( col_count <= row_count ) // col_count = 1, 2, ..., row_count
{
System.out.printf("*");
col_count++;
}
System.out.printf("\n");
row_count++;
}
}
}
But I'm not sure how to translate this into the next part of the assignment. Thanks for any help!
Edited by: Robdog0077 on Mar 9, 2010 11:45 AM