- Engineering
- Computer Science
- trying to figure out how to correct the error i...
Question: trying to figure out how to correct the error i...
Question details
Trying to figure out how to correct the error I am getting. The
code is posted below. Thanks
import java.util.Scanner;
public class BarGraph2 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Number of values to graph: ");
int n = in.nextInt();
int data[] = new int[n];
int max = 0;
for(int i=0; i
data[i] = in.nextInt();
if(max < data[i]) {
max = data[i];
}
}
System.out.print("Bar graph for ");
for(int i=0; i
System.out.print(data[i]+ " ");
}
System.out.println(":");
for(int height = max; height > 0; height--) {
for(int i=0; i
if(data[i] >= height) {
System.out.printf("%3s", "#");
} else {
System.out.printf("%3s", " ");
}
}
System.out.println();
}
for(int i=0; i
System.out.printf("---");
}
System.out.println();
for(int i=0; i
System.out.printf("%3d", data[i]);
}
System.out.println();
}
}
Solution by an expert tutor
