Results 1 to 4 of 4
  1. #1
    Strawlion is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Default Drawing shapes with for loops using characters

    Hey guys, I'm trying to draw a shape that looks like this
    $$$*
    $$*$
    $*$$
    *$$$

    However with this code it comes out as

    $$$*
    $$$*
    $$$*
    $$$*

    The beginning part of my code asks the user which shape they would like to be drawn, and the size of the shape. This is the code pertaining to the "diagonal"

    else if (shape.equals("diagonal"))
    for(int i=0; i<size; i++){
    for(int j=0; j<size; j++){
    System.out.print("$$$*");
    }
    System.out.println();

    }
    How would I go about shifting each subsequent row to the left by 1?

    Thanks in advance :)

  2. #2
    Ruuhkis is offline Member
    Join Date
    Feb 2011
    Posts
    19
    Rep Power
    0

    Default

    public class printDollar {
    public static void main(String args[]){
    StringBuilder dollar;
    for(int x = 3; x > -1; x--){
    dollar = new StringBuilder("$$$");
    dollar.insert(x, '*');
    System.out.println(dollar);
    }
    }
    }
    You want something like this?

  3. #3
    Strawlion is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Default

    Yeah, that's what I want. However I'm including this line in my code

    System.out.println("Enter a size");
    int size = scan.nextInt();

    To delegate how many rows/columns there will be.
    ie if size =6

    $$$*$$
    $$*$$$
    $*$$$*
    *$$$*$
    $$$*$$
    $$*$$$

    Thanks

  4. #4
    Strawlion is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Default

    For example, this is what my code looks like for drawing a "triangle"

    else if (shape.equals("triangle"))
    for(int i=0; i<size; i++){
    for(int j=size-i-1;j >= 0; j--){
    System.out.print(" ");
    }
    for(int k=0; k<i+1 ; k++ ){
    System.out.print("*");

    }
    System.out.println();
    }

Similar Threads

  1. java shapes
    By Kyle227 in forum New To Java
    Replies: 7
    Last Post: 05-20-2010, 01:21 AM
  2. erase shapes ???
    By h9h in forum Java 2D
    Replies: 1
    Last Post: 10-12-2009, 09:11 PM
  3. drawing shapes in java help
    By alphajoseph in forum Java 2D
    Replies: 2
    Last Post: 09-29-2009, 07:35 PM
  4. Help with ASCII Drawing--For loops--if/else
    By alice.li.mastriano in forum New To Java
    Replies: 1
    Last Post: 09-13-2009, 01:31 AM
  5. Getting User Input to Drawing Shapes
    By mlfatty in forum AWT / Swing
    Replies: 2
    Last Post: 03-04-2009, 07:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •