一直出现找不到符号,调式了半天还是有问题
import javax.swing.*;
public class Histogram
{
public static void main(String[] args){
int array[] = { 12, 3, 5, 3, 15, 9, 2, 9, 6, 8 };
String output = "Element\tValue\tHistogram"; for( int counter = 0; counter < array.length; counter++ )
output += "\n" + counter + "\t" + array[counter] + "\t";

for( int stars = 0; stars < array[counter]; stars++ )//找不到符号
output += "*"; JTextArea outputArea = new JTextArea();
outputArea.setText(output); JOptionPane.showMessageDialog( null, outputArea,
"Histogram Printing Program", 
JOptionPane.INFORMATION_MESSAGE );
System.exit(0);
}
}

解决方案 »

  1.   

    import javax.swing.*;
    public class Histogram
    {
    public static void main(String[] args){
    int array[] = { 12, 3, 5, 3, 15, 9, 2, 9, 6, 8 };
    String output = "Element\tValue\tHistogram"; for( int counter = 0; counter < array.length; counter++ )
    {
    output += "\n" + counter + "\t" + array[counter] + "\t";

       for( int stars = 0; stars < array[counter]; stars++ )//找不到符号
       output += "*";
       } JTextArea outputArea = new JTextArea();
    outputArea.setText(output); JOptionPane.showMessageDialog( null, outputArea,
    "Histogram Printing Program", 
    JOptionPane.INFORMATION_MESSAGE );
    System.exit(0);
    }
    }
      

  2.   

    import javax.swing.*;
    public class Histogram
    {
    public static void main(String[] args){
    int array[] = { 12, 3, 5, 3, 15, 9, 2, 9, 6, 8 };
    String output = "Element\tValue\tHistogram";
    int counter;
    for(counter = 0; counter < array.length-1; counter++ )
    output += "\n" + counter + "\t" + array[counter] + "\t";for( int stars = 0; stars < array[counter]; stars++ )//找不到符号
    output += "*";JTextArea outputArea = new JTextArea();
    outputArea.setText(output);JOptionPane.showMessageDialog( null, outputArea,
    "Histogram Printing Program",
    JOptionPane.INFORMATION_MESSAGE );
    System.exit(0);
    }
    }变量的可见性.counter在for()内可见,在for外不可见,所以找不到符号.
      

  3.   

    三楼才是对的,因为counter 在第一个for中定义,for 一结束,counter 就释放了。因为找不到符号。