Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2010
    Posts
    7
    Rep Power
    0

    Default Can someone look over this java program please?

    Its suppose to output a triangle depending on the users input
    ex

    input-3
    output
    3
    33
    333
    33
    3
    input-7
    output
    7
    77
    777
    7777
    77777
    777777
    7777777
    777777
    77777
    7777
    777
    77
    7

    I know that right now it won't really work for numbers over 9


    here it is



    import java.util.Scanner;

    public class TriangleOfDigits
    {
    public static void main(String[] args)
    {
    Scanner input = new Scanner(System.in);
    int rows = input.nextInt();
    //outer loop says how many lines
    //*n by 2 and - 1 (how many lines needed

    for (int rowNumber = 1; rowNumber <= rows; rowNumber++);
    {
    //inner loop says how many things on this line
    for(int colNum = 1; colNum <= rowNumber; colNum++);

    {

    //print out thing
    System.out.print(rows);
    }

    System.out.println();
    }

    for (int rowNumber = 1; rowNumber <= rows; rowNumber++);
    {
    //inner loop says how many things on this line
    for(int colNum = rows; colNum > rowNumber; colNum--);
    {
    //print out thing
    System.out.print(rows);
    }

    }



    System.out.println();
    }
    }




    These are the error messages Im getting


    TriangleOfDigits.java:16: cannot find symbol
    symbol : variable rowNumber
    location: class TriangleOfDigits
    for(int colNum = 1; colNum <= rowNumber; colNum++);
    ^
    TriangleOfDigits.java:31: cannot find symbol
    symbol : variable rowNumber
    location: class TriangleOfDigits
    for(int colNum = rows; colNum > rowNumber; colNum--);




    Im not quite sure how to fix this

    thanks in advance

  2. #2
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    305
    Rep Power
    6

    Default

    You're for loops shouldn't have the ';' after the declaration. It should look like this.
    Java Code:
        for (int i = 0; i < list.size(); i ++) {
              //your code here...
        }
    Take the ';' off the for loops and see what you get.

  3. #3
    Join Date
    Nov 2010
    Posts
    7
    Rep Power
    0

    Default

    @StormyWaters
    thanks you very much! It works perfectly now.
    :)

Similar Threads

  1. Replies: 8
    Last Post: 09-30-2010, 06:32 PM
  2. Replies: 4
    Last Post: 07-30-2010, 12:25 PM
  3. execute java program within java program
    By popey in forum New To Java
    Replies: 2
    Last Post: 10-22-2009, 05:32 PM
  4. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 PM

Tags for this Thread

Posting Permissions

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