- Version
- Download 18
- File Size 2.43 KB
- File Count 1
- Create Date April 26, 2016
- Last Updated April 26, 2016
Count number of characters in Java
Count number of characters in Java
This is an example of java program that will ask you to enter a string, and then the program will count the number of characters of that string. This is also coded in gui and console format.
Source code:
import javax.swing.*;
class CountStringGUI {
public static void main(String[] args) {
String mystring;
mystring = JOptionPane.showInputDialog(null,"Enter a string: ");
JOptionPane.showMessageDialog(null,"the string: " + mystring + " has " + mystring.length() + " characters.");
}
}