提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
条形图打印程序。
public class Main {//来自 n o w j a v a . c o m public static void main(String[] args) { int[] array = {0, 0, 0, 1, 0, 0, 1, 2, 4, 2, 1}; System.out.println("Grade distribution:"); // for each array element, output a bar of the chart for (int counter = 0; counter < array.length; counter++) { // output bar label ("00-09: ", ..., "90-99: ", "100: ") if (counter == 10) System.out.printf("%5d: ", 100); else/*来自 时代Java - nowjava.com*/ System.out.printf("%02d-%02d: ", counter * 10, counter * 10 + 9); // print bar of asterisks for (