Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Programming Java Help

  • 13-01-2009 8:28pm
    #1
    Closed Accounts Posts: 1


    can anybody help me quickly
    this my code for java
    when run for example input = 3 you get the following output
    ***
    **
    *
    what i need is this
    *
    **
    ***
    **
    *

    this is a matter of urgency my email is sipod06@hotmail.com

    my code

    import java.util.Scanner;

    //prints a triangle of *s, as wide as the user specifies
    public class Document1
    {
    public static void main(String[] args)
    {
    Scanner in = new Scanner(System.in);

    //prompts user to input a number
    System.out.print("Please input a number: ");
    //saves the user's number into n
    int n = in.nextInt();
    //declares row variable
    int row;

    while (n > 0)
    {
    row = n;
    while (row > 0)
    {
    //prints the * character
    System.out.print("*");
    //decrements row
    row--;
    }
    //goes to the next line
    System.out.println();
    //decrement n
    n--;
    }
    }
    }
    Tagged:


Comments

  • Registered Users, Registered Users 2 Posts: 1,119 ✭✭✭Donald-Duck


    Have it print from 0 to n-1 before printing from n to 0


  • Registered Users Posts: 61 ✭✭GavinJCD


    I think you should go back to the IMACD's there Simon, you won't be programming the new windows anytime soon, they would have to rename it to Winblows. Or windows Vista the second coming.

    Either way, I can see a lot of forms in your future. Oh yeh and Aillin says hi.


  • Registered Users, Registered Users 2 Posts: 17,727 ✭✭✭✭Sherifu


    Using for loops would probably be easier on the eye, that and using Donald-Duck's advice.


Advertisement