Count number of characters in Java

Download
Download is available until [expire_date]
  • 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.");
}
}
, , , , , ,

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.