Counts the number of uppercase letters, lowercase letters, and numbers in a string. __ Personal Practice

Source: Internet
Author: User

public class Stringtest {
public static void Main (string[] args) {
Encapsulating keyboard Input data
Scanner sc = new Scanner (system.in);
System.out.println ("Please enter a string:");
String line = Sc.nextline ();

Defining statistical variables
int big = 0;
int small = 0;
int number = 0;

  //length,charat
  for (int x = 0; x < line.length () + x + +) {
   //get each Characters
   char ch = line.charat (x);
   if (ch >= ' 0 ' && ch <= ' 9 ') {
    number++;
   } else if (ch >= ' A ' && ch <= ' Z ') {
    big++;
 &nb SP;&NBSP} else if (ch >= ' a ' && ch <= ' z ') {
    small++;
   }   }
  
  system.out.println ("The number of uppercase letters in the string appears:" +big);
  system.out.println ("The number of lowercase letters in the string appears:" +small); The number occurrences in the
  system.out.println ("string) are:" +number);
  
 }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.