Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java array printing asterisk

Tags:

java

arrays

I know this is just a simple java array problem, but I don't have any idea how to do this.What I want to do is like this:

Student    Score    Graph
John                3    ***
Mark                2    **
James              1    *

What I have in mind is an array like this:

String[][] students = { { "John", "Mark", "James" }, { "3", "2", "1" } };

How will I print the line graph without adding another set of variables in the array? I want it to just display asterisks (*) according to the number of score.


1 Answers

Like this?

int gradeAsInt = Integer.parseInt (students [1][n]);
for (int i = 0; i < gradeAsInt; ++i) System.out.print ("*");
like image 197
JohnB Avatar answered Aug 28 '26 23:08

JohnB



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!