Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: I want the java coding to print following # pattern in cmd.exe . So pls help me .. It must start with 6 #'s and end with 2 #'s .

  1. #1
    Junior Member
    Join Date
    Sep 2017
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post I want the java coding to print following # pattern in cmd.exe . So pls help me .. It must start with 6 #'s and end with 2 #'s .

    ######
    #####
    ####
    ###
    ##

  2. #2
    Junior Member
    Join Date
    Sep 2017
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post I want the java coding to print following # pattern in cmd.exe . So pls help me .. It must start with 6 #'s and end with 2 #'s .

    ######
    #####
    ####
    ###
    ##

  3. #3
    Member
    Join Date
    Aug 2017
    Location
    Northern Ireland
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I want the java coding to print following # pattern in cmd.exe . So pls help me .. It must start with 6 #'s and end with 2 #'s .

    We've established what the goal is, that's good. Now it's time for you to tell us how far you've gotten with it and perhaps you want to ask a question about a specific part you're currently stuck on?
    Tim Driven Development

  4. #4
    Junior Member
    Join Date
    Sep 2017
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I want the java coding to print following # pattern in cmd.exe . So pls help me .. It must start with 6 #'s and end with 2 #'s .

    public class pattern {
    public static void main(String[] args) {

    for (int row = 6; row >= 2; ++row){
    for (int col = 1; col <= row; --col){
    System.out.print("#");
    }
    System.out.println();
    }
    }
    }

  5. #5
    Member
    Join Date
    Aug 2017
    Location
    Northern Ireland
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I want the java coding to print following # pattern in cmd.exe . So pls help me .. It must start with 6 #'s and end with 2 #'s .

    Does that do what you need?

    Also, it's advisable to use code tags around your code to make it easier to read. For example, here's your code again with code tags.
    public class pattern {
      public static void main(String[] args) {
     
        for (int row = 6; row >= 2; ++row){
          for (int col = 1; col <= row; --col){
            System.out.print("#");
          }
          System.out.println();
        }
      }
    }
    It looks a lot better right?

    Now, does that code do what you need it to? What's the output of it?
    Tim Driven Development

  6. #6
    Junior Member
    Join Date
    Sep 2017
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I want the java coding to print following # pattern in cmd.exe . So pls help me .. It must start with 6 #'s and end with 2 #'s .

    ok..thanks, the output is terrible.... it shows unending #'s.

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: I want the java coding to print following # pattern in cmd.exe . So pls help me .. It must start with 6 #'s and end with 2 #'s .

    shows unending #'s.
    You need to work out the logic first.
    How many lines need to be printed?
    What logic is needed to stop printing #s after the required number are printed for the current line?
    How many #s are printed on each line?
    How does that compare to the number printed on the previous line?
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Junior Member
    Join Date
    Sep 2017
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I want the java coding to print following # pattern in cmd.exe . So pls help me .. It must start with 6 #'s and end with 2 #'s .

    Capture.jpg


    above pic is a screenshot of my output..
    pls ..i have no idea how the code interconnects with the pattern.....It's better if someone(who knows) can give me the code........I want following output...

    ######
    #####
    ####
    ###
    ##

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: I want the java coding to print following # pattern in cmd.exe . So pls help me .. It must start with 6 #'s and end with 2 #'s .

    Sorry, we don't provide code.
    You need first to work out the logic.
    Consider these points:
    how many lines need to be printed? Use a loop for the required number of lines.
    the loop control variable normally increases, but it can also decrease. Going from 0 to 5 and from 5 to 0 gives that same number of loop iterations.

    Next how many #s are to be printed on the first line?
    Then how many on the second line? Hint: one fewer. fewer implies subtracting from a counter

    Your code looks close. Make sure the loop variables are changing value in the right direction: increasing or decreasing as is required.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Need help on pattern print problem
    By DotNet13 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 25th, 2013, 07:14 AM
  2. Replies: 4
    Last Post: September 6th, 2012, 05:29 AM
  3. to print pattern
    By Charanleen in forum What's Wrong With My Code?
    Replies: 9
    Last Post: October 3rd, 2010, 07:54 AM
  4. [SOLVED] selection end and start
    By nasi in forum What's Wrong With My Code?
    Replies: 13
    Last Post: May 10th, 2010, 04:05 AM
  5. cmd.exe DOS Window
    By Curious in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: March 1st, 2010, 10:30 AM

Tags for this Thread