|
Issue for Scanner Input and Loops
Hi guys, I am trying to solve a bug here. My scanner doesn't recognize the "Rows" input. The output of these code suppose to be, for example, the row=1, one triangle is drawn, and for row=2, two, and so on. but it keeps getting 3 rows here as shown on the output.
The assignment is due in 2 hours, will really appreciate to someone's help! Thanks!
code--------------
import java.util.Scanner;
public class drawTriangle {
public static final int Size = 3;
public static final int Rows = 2;
public static final char Char1 = '0';
public static final char Char2 = '*';
public static void main(String[] args) {
drawRowOne();
drawRowTwo();
drawRowThree();
for (int y=1; y< Rows; y++){
//drawRowY(y);
System.out.print(" ");
}
}
private static void drawRowY() {
for (int x = 0; x <= Rows; x++){
System.out.print(Char1);}
//borders, could be 0
//triangles, could be 1
//borders, could be 0
}
private static void drawRowOne() {
for( int x=0; x<= Size; x++){
drawBox();
drawBox();
drawTriangle(x);
drawBox();
drawBox();
System.out.println();
}
}
private static void drawRowTwo(){
for( int x = 0; x <= Size; x++){
drawBox();
drawTriangle(x);
drawTriangle(x);
drawBox();
System.out.println();
}
}
private static void drawRowThree(){
for( int x = 0; x <= Size; x++){
drawTriangle(x);
drawTriangle(x);
drawTriangle(x);
System.out.println();
}
}
private static void drawTriangle(int i){
for(int j = 0; j <=i; j++) {
System.out.print(Char1);
}
for (int j = 0; j < Size-i; j++){
System.out.print(Char2);
}
for (int j = 0; j < Size-i; j++){
System.out.print(Char2);
}
for (int j = 0; j <= i; j++){
System.out.print(Char1);
}
}
private static void drawBox() { //row
for (int x = 0; x <= Size; x++){
System.out.print(Char1);
}
}
}
------------------------output
000000000******000000000
0000000000****0000000000
00000000000**00000000000
000000000000000000000000
00000******00******00000
000000****0000****000000
0000000**000000**0000000
000000000000000000000000
0******00******00******0
00****0000****0000****00
000**000000**000000**000
000000000000000000000000
Last edited by ronron629; 05-07-2011 at 05:31 AM..
|