Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-07-2011, 05:25 AM   PM User | #1
ronron629
New to the CF scene

 
Join Date: Apr 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
ronron629 is an unknown quantity at this point
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..
ronron629 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:39 PM.


Advertisement
Log in to turn off these ads.