1 2 Previous Next 19 Replies Latest reply on Jul 30, 2010 8:59 AM by 3004

    print integer numbers in Specfic Format

    843789
      Hi,
      How to print integer numbers as below in java. Can you please help me to get the solution.

      1
      2 3
      4 5 6
      7 8 9 10
      11 12 13 14
      ..................so on

      regards
      Sandeep
        • 1. Re: print integer numbers in Specfic Format
          3004
          This is not a code writing service. Take a stab at doing your own work, then show your work and post a more specific question when you get stuck.
          • 2. Re: print integer numbers in Specfic Format
            791266
            696969 wrote:
            Hi,
            How to print integer numbers as below in java. Can you please help me to get the solution.

            1
            2 3
            4 5 6
            7 8 9 10
            11 12 13 14
            ..................so on
            ... and so on? I still don't see the logic. The 4th and 5th line both have 4 numbers.
            • 3. Re: print integer numbers in Specfic Format
              843789
              sorry,
              it has to be,

              1
              2 3
              4 5 6
              7 8 9 10
              11 12 13 14 15
              ..................so on(six numbers need to display)

              regards
              • 4. Re: print integer numbers in Specfic Format
                3004
                See reply 1.

                What is your question?

                "How do I do start?" is not a valid question. [http://home.earthlink.net/~patricia_shanahan/beginner.html]
                • 5. Re: print integer numbers in Specfic Format
                  791266
                  696969 wrote:
                  sorry,
                  it has to be,
                  Open your textbook and read about loops.
                  • 6. Re: print integer numbers in Specfic Format
                    843789
                    Please just give me clue,, not the code. i tried with numerous logic,but i could not crack it.

                    regards
                    • 7. Re: print integer numbers in Specfic Format
                      3004
                      696969 wrote:
                      Please just give me clue,,
                      There are many clues already available. They're in any textbook or tutorial. And here's another great one: [http://home.earthlink.net/~patricia_shanahan/beginner.html]

                      And here's one more: Figure out how you'd do it "manually" first--without Java or any other programming language.
                      i tried with numerous logic,but i could not crack it.
                      We don't know what you tried and in what way it didn't work.
                      • 8. This Thread is now moved
                        darrylburke
                        Note: This thread was originally posted in the [Java Programming|http://forums.sun.com/forum.jspa?forumID=31] forum, but moved to this forum for closer topic alignment.
                        • 9. Re: print integer numbers in Specfic Format
                          794029
                          696969 wrote:
                          Please just give me clue,, not the code. i tried with numerous logic,but i could not crack it.

                          regards
                          do you know how to use a for loop?
                          do you know how to print a line of code or a number?

                          Start by writing a program that prints:

                          1
                          2
                          3
                          4
                          5
                          ...
                          (and show your code)
                          • 10. Re: print integer numbers in Specfic Format
                            843789
                            Why hasn't anyone suggested the obvious?
                            public class AndSoOn {
                               public static void main(String[] args) {
                                  System.out.println("1");
                                  System.out.println("2 3");
                                  System.out.println("4 5 6");
                                  System.out.println("7 8 9 10");
                                  System.out.println("11 12 13 14");
                                  System.out.println("..................so on");
                               }
                            }
                            • 11. Re: print integer numbers in Specfic Format
                              843789
                              Shame on you Enc! Don't you realise OP needs a loop?
                              public class AndSoOn {
                                 public static void main(String[] args) {
                                    Strin[] foo = {"1", "2 3", "4 5 6", "7 8 9 10", "11 12 13 14", "..................so on"};
                                    for (int i = 0; i < foo.length; i++) {
                                      System.out.println(foo);
                              }
                              }
                              }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
                              • 12. Re: print integer numbers in Specfic Format
                                843789
                                Shame on both of you.
                                I recommend getting these books.
                                Introduction to Java Programming (Y. Daniel Llang)
                                Absolute Java

                                Two of the best that i have seen.

                                First Step Into Java - Dev Shed. This one to me at first seemed quite good. But then it started to feel like it was trying to teach Java to a 5th grader. The way it was written comes across as condescending.

                                There is no short cut and the best way you will learn is to read books.
                                • 13. Re: print integer numbers in Specfic Format
                                  3004
                                  fersick wrote:
                                  Shame on both of you.
                                  It appears your sarcasm detector is broken.
                                  • 14. Re: print integer numbers in Specfic Format
                                    843789
                                    Guys,
                                    It's not about printing,, if i provide 20 as in input then out put has to be

                                    1
                                    2 3
                                    4 5 6
                                    7 8 9 10
                                    11 12 13 14 15.

                                    regards
                                    1 2 Previous Next