一直出现找不到符号,调式了半天还是有问题
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);
}
}
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);
}
}
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);
}
}
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外不可见,所以找不到符号.