nested for loops
what is the programming code to make a program that will ask the user to input the height of a mountain?
for example, if they input 4 as the height of the mountain, the program should say but inverted, with the tip of the mountain touching the left and the base on the right:
*
**
***
****
***
**
*
[354 byte] By [
x3virgiea] at [2007-11-27 9:41:36]

Play with the for loops. Do you know what nested for loops are?
for(int i=0; i<number; i++){
for(int j=0; j>< someothernumber; j++){
for(int k=0;k<somenumber;k++{
}//end for k
}//end for j
}//end for for i
Play around with things like that and you'll get it.
Btw, don't get the Iphone, sales must not reach 1.5 million.
->
import java.util.Scanner;
class mountain
{
public static void main (String args[])
{
Scanner input = new Scanner ( System.in );
int i,j, num;
System.out.print("Enter height of the mountain: ");
num=input.nextInt();
{for(i=0; i<=num;i++)
{for(j=1;j<i;j++)
System.out.println(" ");
{System.out.print("*");
}
}
}
{for(i=0;i<num;i++)
{for(j=num;j>i;j--)
System.out.println(" ");
{System.out.print("*");
}
}
}
}
}
that is the code for the original one but we need to invert it.
For starters, note the difference between print and println, and ask yourself, "when do I need to terminate the current line by writing the line separator string?".