| //
program to count number of '9' in a string by Hing Tze
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Application1
{
public Application1()
{
String s = ("ew923khddf39987234dk3i4928dj3s");
int counter; // loop counter
int total = 0;
char c; // char variable
for (counter=0; counter<=29; counter = counter + 1)
{
c = s.charAt(counter);
if (c == '9')
{
total = total + 1;
}
}
JOptionPane.showMessageDialog(null,"total number
of 9's = " + total);
}
public static void main(String args[])
{
Application1 app = new Application1();
System.exit(0);
}
} |