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

1. Member
Join Date
Jan 2012
Location
Chicago, Illinois, USA
Posts
19
Rep Power
0

## 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!

2. Senior Member
Join Date
Jun 2007
Location
Bali, Indonesia
Posts
762
Rep Power
11

## 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.

3. Member
Join Date
Jan 2012
Location
Chicago, Illinois, USA
Posts
19
Rep Power
0

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

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.

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.

4. Senior Member
Join Date
Jun 2007
Location
Bali, Indonesia
Posts
762
Rep Power
11

## 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.
Java 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.

5. Member
Join Date
Jan 2012
Location
Chicago, Illinois, USA
Posts
19
Rep Power
0

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

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.

6. Senior Member
Join Date
Jun 2007
Location
Bali, Indonesia
Posts
762
Rep Power
11

## 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.

7. Member
Join Date
Jan 2012
Location
Chicago, Illinois, USA
Posts
19
Rep Power
0

## 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 :-)

8. Member
Join Date
Jan 2012
Location
Chicago, Illinois, USA
Posts
19
Rep Power
0

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

Here is what I got from my instructor:

Java 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();
}
}```

9. Senior Member
Join Date
Jun 2007
Location
Bali, Indonesia
Posts
762
Rep Power
11

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

Yes, that's work. It draws a letter N for you. In this case you just print out the '*' and the empty spaces, without using an array as a temporary storage.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•