English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

can anybody show me how to do this:

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

2007-01-10 02:11:05 · 3 answers · asked by trickyme 1 in Computers & Internet Programming & Design

3 answers

public class Test{
public static void main(String[] args) {
int max = 4;
for(int i = 1; i <= max; i++) print(i);
for(int i = max - 1; i > 0; i--) print(i);
}
static void print(int n) {
for(int i = 0; i < n; i++) System.out.print("*");
System.out.println();
}
}

2007-01-10 02:54:46 · answer #1 · answered by FXJKHR 3 · 0 0

public class Pyramid {

public static void main(String[] args) {

int i;
int j;
int depth = 4;

for( i = 1; i < (depth * 2); i++) {

for( j = 1; j <= (depth-Math.abs(i-depth)); j++) {

System.out.print( "*");
}

System.out.println("");
}
}
}


You can also change

int depth = 4;

to

int depth = Integer.parseInt( args[ 0]);

to change the depth via the command-line. Just make sure you have a default value in case there are no arguments.

2007-01-10 12:43:40 · answer #2 · answered by Kookiemon 6 · 0 0

Sure.. but i need more details, please contact me and I'll show you.
messenger or mail: manuel220@yahoo.com

2007-01-10 10:24:21 · answer #3 · answered by manuel220 3 · 0 0

fedest.com, questions and answers