Exercise: Bar Chart

Write a program that lets the user enter numbers separated by space characters, for example "10 23 50". For each number, your program prints a bar using the asterisk character *. The bar must be as long as the entered number.

For example (user input in green):

Enter a few numbers, separated by spaces: 10 23 50
10 → **********
23 → ***********************
50 → **************************************************

Another example

Enter a few numbers, separated by spaces: 2 0 1 3
2 → **
0 →
1 → *
3 → ***

Hint 💡

To access a character in a string, you can use the charAt method. For example, "hello".charAt(0) returns the character 'h'. You can also use the length field to get the length of a string. For example, "hello".length returns 5.

Hand in instructions

  1. Make sure your program runs correctly.
  2. Hand in your program by uploading Main.java to Moodle.