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 5 of 5

Thread: [HELP] [HELP] Trouble To Understanding The Algorithm of my project

  1. #1
    Member
    Join Date
    Mar 2014
    Posts
    36
    My Mood
    Confused
    Thanks
    20
    Thanked 1 Time in 1 Post

    Default [HELP] [HELP] Trouble To Understanding The Algorithm of my project

    So, Let's get to the point. I need some hint for the algorithm for my project.
    The program should has the output depending the number I'll input. (The number should be from 1-9)
    This is the program's output should be:

    Input number: 4
     
    Output:
    # # # 1 # # # # # 
    # # # 2 # # # # # 
    # # # 3 # # # # # 
    1 2 3 4 5 6 7 8 9 
    # # # 5 # # # # # 
    # # # 6 # # # # # 
    # # # 7 # # # # # 
    # # # 8 # # # # # 
    # # # 9 # # # # #
     
     
    (Example 2):
    Input numbers: 8
    Output:
    # # # # # # # 1 # 
    # # # # # # # 2 # 
    # # # # # # # 3 # 
    # # # # # # # 4 # 
    # # # # # # # 5 # 
    # # # # # # # 6 # 
    # # # # # # # 7 # 
    1 2 3 4 5 6 7 8 9 
    # # # # # # # 9 #
     
    (Example 3):
    Input number: 5
    Output:
    # # # # 1 # # # # 
    # # # # 2 # # # # 
    # # # # 3 # # # # 
    # # # # 4 # # # # 
    1 2 3 4 5 6 7 8 9 
    # # # # 6 # # # # 
    # # # # 7 # # # # 
    # # # # 8 # # # # 
    # # # # 9 # # # #

    Anyone can help me? I'm not asking the code to make this program, I have trouble to understand the algorithm to make this program
    Sorry, my English isn't good enough.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: [HELP] [HELP] Trouble To Understanding The Algorithm of my project

    A pattern of rows and columns printed with 2 loops (one nested in the other) with special characters output on the designated row and column.

    I suggest you start by writing nested loops that print a 9x9 block of '#' symbols and then work on the input/special row and column part. The outer loop controls the rows, the inner loop prints the character along each row making the columns.

    Surely you've done something similar.

  3. #3
    Member
    Join Date
    Mar 2014
    Posts
    36
    My Mood
    Confused
    Thanks
    20
    Thanked 1 Time in 1 Post

    Default Re: [HELP] [HELP] Trouble To Understanding The Algorithm of my project

    Yes I've done something similar, Do you mean like this?
    package projek1;
    /**
     *
     * @author Hengky
     */
    public class Projek1 {
        public static void main(String[] args) {
            for (int i = 1; i <= 9; i++) {
     
                for (int j = 1; j <= 9; j++) {
                    System.out.print('#');    
                }
                System.out.println("");
     
            }
        }
     
    }
     
    The output:
    #########
    #########
    #########
    #########
    #########
    #########
    #########
    #########
    #########

    I just change the print '#' into j if I want the ouput print numbers, right?
    Then from here what next?

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: [HELP] [HELP] Trouble To Understanding The Algorithm of my project

    Excellent start!

    First get the user's input (use a Scanner object), then you'll use an 'if' statement to do pretty much what you've described, something like:
    if ( j = userInput )
    {
        // do something different
    }
     
    if ( i = userInput )
    {
        // do something different
    }

  5. The Following User Says Thank You to GregBrannon For This Useful Post:

    noobies (April 15th, 2014)

  6. #5
    Member
    Join Date
    Mar 2014
    Posts
    36
    My Mood
    Confused
    Thanks
    20
    Thanked 1 Time in 1 Post

    Default Re: [HELP] [HELP] Trouble To Understanding The Algorithm of my project

    Hey Thanks!! I Solved this because your help.
    I have another project, I hope you can guide me to complete the project like what you did in my thread here
    This is the thread:
    http://www.javaprogrammingforums.com...tml#post145346
    Sorry if this trouble you.

Similar Threads

  1. Trouble understanding what this is asking.
    By daniel95 in forum Object Oriented Programming
    Replies: 7
    Last Post: October 29th, 2013, 05:19 PM
  2. Having trouble understanding recursive methods??
    By orbin in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 17th, 2012, 01:08 AM
  3. Having trouble understanding Int Logs.
    By orbin in forum What's Wrong With My Code?
    Replies: 10
    Last Post: October 10th, 2012, 12:30 PM
  4. Inheritance trouble understanding how to use it?
    By orbin in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 21st, 2012, 11:24 AM
  5. Replies: 3
    Last Post: July 12th, 2012, 07:11 AM