// ------------------------------------------- // OCCURRENCES : DECOMPTE DE LETTRES // ------------------------------------------- import java.applet.*; import java.awt.*; public class Occurrences extends Applet { String chaine; public void init() { // Couleur de fond setBackground(Color.black); // Une chaîne de caractères... chaine = "Les serpents de mer se sont sauvés"; } // Affichage public void paint(Graphics g) { int i = chaine.indexOf("s"); int j = 0 ; while (i != -1) { j++; i = chaine.indexOf("s", i+1); } g.setColor(Color.yellow); g.drawString(chaine, 10, 15); g.drawString("Nombre de s : "+ j, 10, 30); } }