if
statement.
The best way to show this is to indent the statements that are inside. To do this you move the statements to the right by a few spaces. People commonly use two, three, or four spaces. Choose one number (eg, I use 2 or 3), and use it for all programs.
Java doesn't care about your indentation -- it is for humans (including yourself!).
paintComponent()
method from a previous page without
indentation. This is small, so it's easy to see which statements
are in the true and false parts. If the if
statement is
much larger, it will be unreadable without indentation.
public void paintComponent(Graphics g) { super.paintComponent(g); if (marks < 50) g.setColor(Color.red); else g.setColor(Color.black); g.drawString("Score = " + marks, 10, 50); }
public void paintComponent(Graphics g) {super.paintComponent(g);if (marks<50)
g.setColor(Color.red);else g.setColor(Color.black);g.drawString("Score = " + marks,10,50);}