I sound really silly for asking this, but I'm having trouble with my for loop.
Here is part of the code I'm having trouble with.
Scanner input = new Scanner( System.in);
int number;
for(int i = 0;i < 5;i++) {
System.out.print("Enter 5 integers:");
number = input.nextInt();
}
When I run it the print out loops more than 5 times.
public class BarGraph extends JPanel
{
public void paintComponent( Graphics g )
{
Scanner input = new Scanner( System.in);
// super.paintComponent(g);
int number;
for(int i = 0;i < 5;i++)
{
System.out.print("Enter 5 integers:");
number = input.nextInt();
// g.drawRect(10 * i, 10 * i, 100 * number, 10);
}
}
}
Running BarGraphTest
public class BarGraphTest
{
public static void main( String[] args)
{
BarGraph panel = new BarGraph();
JFrame application = new JFrame();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
application.add( panel );
application.setSize( 300, 300);
application.setVisible( true );
}
}
Basically what I'm trying to do is read 5 integers and just display them on JPanel line a bar graph.