I have to make a code thats contain a method that takes a vector of integers as a parameter and, from their values, prints a horizontal bar graph on the screen. I Just cant print the amount of characters with the value of the string. Rigth now i have a list in a method:
class Main {
public static void main(String args[]) {
exibeGraficoDeBarras();
}
static void exibeGraficoDeBarras(){
int lista[]={4,12,10,14,17,9};
for (int i = 0; i<lista.length; i ){
for (int j = 0; j<lista[i]; j ){
System.out.print("#");
}
System.out.println();
}
}
}
And the output should be like this:
"########## 10"
"##### 5"
"####### 7"
Just add the "" cause the formatting
CodePudding user response:
You need 3 things:
for (int i = 0; i < 10; i ) { code goes here }
runs the part in 'code goes here' 10 times. You can putfor
loops in the code goes here section too.list[0]
accesses the first item in your list (10
, in your case).0
can bei
too, of course.System.out.print(thingie)
prints things. thingie can be"#"
to print a hash, for example, ori
, of course, that works too.System.out.println()
then finishes the line.
This sure sounds like 'help! How do I java?'. Generally, SO is not the right site for such a question. Search the web for a tutorial, there are tons of them - oracle has one, youtube is filled to the brim with them. I don't know how to answer your question in any further detail without just straight up giving you the completed code, which clearly would fail to accomplish the required goal here (which is: That you learn something).