# How to produce a large N that is # characters tall

• 04-24-2012, 04:07 AM
eviljeff
How to produce a large N that is # characters tall
Hello. I need to learn how to write a program that asks the user for a value of size until a positive integer is entered. After the positive integer is entered, the program produces a large N that is size characters tall.

All I need to know is how to get the output in that format. I think I use a for loop, but I'm not sure what to use to make the characters align in the shape of a N. I would appreciate any help on this. Thanks!
• 04-24-2012, 04:26 AM
Re: How to produce a large N that is # characters tall
You can use the java.util.Scanner object to get user input. Use the while loop to repeat until the user enter a valid number.

To draw the N letter you can utilize a matrix / two dimension array to store the letter structure. Then you need to define how to draw the vertical part of the N letter and the diagonal part of the N letter. Pencil and paper drawing can help you to find the logic.
• 04-24-2012, 06:22 AM
eviljeff
Re: How to produce a large N that is # characters tall
Quote:

To draw the N letter you can utilize a matrix / two dimension array to store the letter structure.

The problem is from a Practice exam, and it says I just need to write the main method. It says assume the scanner class has been imported, but it doesn't say anything about any other class or Java util. This leads me to believe that it can be done without any other imported Java util besides Scanner.

Quote:

Then you need to define how to draw the vertical part of the N letter and the diagonal part of the N letter. Pencil and paper drawing can help you to find the logic.

That's what I need to learn how to do. I don't know how to make the letter N.
• 04-24-2012, 06:30 AM
Re: How to produce a large N that is # characters tall
Yes, you just need to use the Scanner class which is in the java.util package.

This is the letter N representation in an array. In this case the size / tall is six # letters.
Code:

```   012345   ------ 0|#    # 1|##  # 2|# #  # 3|#  # # 4|#  ## 5|#    #```
Now, you need to define the way to draw it for the size defined by user input.
• 04-24-2012, 06:52 AM
eviljeff
Re: How to produce a large N that is # characters tall
Quote:

Now, you need to define the way to draw it for the size defined by user input.

Again, that's the only part I do not know how to do. How do I define the way to draw it for the size defined by user input? That's what I'm asking you, I already know the other stuff.
• 04-24-2012, 07:01 AM
Re: How to produce a large N that is # characters tall
Well, basically I tell you what you need to do to solve it. The user input will define the size of the two dimensional array. On the first and the last column of the array fill it with the '#' symbol. And the calculate the row and column for the diagonal part of the N letter and fill it with the '#' symbol.

When the loop to fill up the array above is done. You just need to loop it and print the value of the array at the row, column position then you'll have the N letter printed out.

Now, it is your turn to implement the Java code for that, and let see what I can do to help you.
• 04-24-2012, 07:10 AM
eviljeff
Re: How to produce a large N that is # characters tall
Okay I see what you're saying. I am going to read the text book on how to print arrays in a structured form, and then I will write the code for the program. Thank you for your help :-)
• 04-25-2012, 06:22 AM
eviljeff
Re: How to produce a large N that is # characters tall
Here is what I got from my instructor:

Code:

```public static void main(String[] args) {     Scanner kbd = new Scanner(System.in);     int size = -1;     int row = -1, col = -1;     char outputChar = '*';     char space = ' ';     while (size < 1)     {         System.out.println("Enter a positive integer for size: ");         size = kbd.nextInt();     }     for (row = 1; row <= size; row++)     {         for (col = 1; col <= size; col++)         {             if (col == 1 || col == size || col == row)                 System.out.print(outputChar);             else                 System.out.print(space);         }         System.out.println();     } }```
• 04-25-2012, 06:31 AM