Basic While Loop

In this example 8 stars are printed by the loop. A counter is used to mark when to exit the loop.

import java.awt.*;
import java.applet.Applet;
public class Stars extends Applet {

public void paint(Graphics g) {

int count = 1;
int x = 10;
while (count < 8) {

g.drawString("*", x, 20);
x = x + 10;
count++;

}

}

}

This is the output

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License