help with nested loops

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • karthikshivram
    New Member
    • Feb 2007
    • 1

    help with nested loops

    im new to java i need help with a code for the following output
    +++++
    ++++
    +++
    ++
    +
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    Originally posted by karthikshivram
    im new to java i need help with a code for the following output
    +++++
    ++++
    +++
    ++
    +
    initially write a program to print
    +

    then add a loop to print
    ++++

    then see if you can figure out how to make it do
    ++++
    +++
    ++
    +

    Comment

    • JavaStudent07
      New Member
      • Jan 2007
      • 64

      #3
      You probably could set "+" equal to a string and to a concatonation, there are a lot of ways to run that program.

      Comment

      • abctech
        New Member
        • Dec 2006
        • 157

        #4
        Originally posted by karthikshivram
        im new to java i need help with a code for the following output
        +++++
        ++++
        +++
        ++
        +
        Try writing the code yourself first..its really easy and then post it if you have any errors or aren't getting the correct output!

        Take a look at this thread, it is not the same as your query but it may give you some idea on how to use loops to get the desired output pattern!

        Comment

        • bala1980
          New Member
          • Feb 2007
          • 3

          #5
          Originally posted by karthikshivram
          im new to java i need help with a code for the following output
          +++++
          ++++
          +++
          ++
          +

          Try the following program

          public class SamplePgm1 {

          /**
          * @param args
          */
          public static void main(String[] args) {

          for(int i = 5; i > 0; i--) {
          for(int j = 0; j < i; j++) {
          System.out.prin t("+");
          }
          System.out.prin tln("");
          }
          }

          }

          Comment

          Working...