I am in the process of taking my first java programming class, and this question may be simple for some of you. Here is the question..

Write an application that reads five numbers between 1 and 30. For each number that is read, your program should display the same number of adjacent asterisks. Display the bars of asterisks after you read all five numbers.

I am wondering what way some of you would solve this problem. I am having trouble writing code that takes an input and displays the same amount of asterisks. Any help is much appreciated. Thanks!

Recommended Answers

All 2 Replies

I assume that since this is your first class you will be using the console to read and write your information.

A good rule of thumb is anytime you need to repeat a task more than once would be to use a loop. The most common types of loops are while loops and for loops.

The best way to approach this type of problem is to break it down into smaller pieces.
1) Read from the console
2) Store the value from the console is some variable
3) Make sure the variable falls in a certain range
4) Output x (the variable) number of asterisks

Take a look at the Java Scanner class to read from the console.

There are some examples of how to use it on that page, as well as countless articles on the web showing examples.

If you run into problems post your code and someone will help you.

Thanks for the info. I was able to figure it out with this help.
Much appreciated!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.