How does Java calculate the number of characters
This article mainly explains "Java how to calculate the number of characters", the content of the explanation is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "Java how to calculate the number of characters" bar!
1. Topic description
Write a program that accepts a string of letters and numbers and spaces, and a character, and then outputs the number of characters in the input string. Case insensitive.
Enter a description:
Enter a string of letters and numbers and spaces, and a character.
Output description:
The number of characters in the output input string.
Input example:
ABCDEFA
Examples of output:
13. Code scheme 1
Basic idea: define String, Char variables-- through getline, cin input variables-- traverse the String array for comparison-- output count.
/ / suitable for any character input # include#include using namespace std; int main () {string inputString; char inputChar; getline (cin,inputString); / / getline reads characters from the standard input device and returns them to the input stream cin, where the data is bound to the variable inputString cin > > inputChar; / / scanf ("% c", & inputChar) / / the above are two ways of input: cin and scanf () int count=0; for (int item0