Initial knowledge java--Programming dot

Source: Internet
Author: User

Requirement: Enter a string to determine if the string contains an uppercase ' A '

Note: This is a nice little trick when you're not learning Java in depth.

1 import Java.util.Scanner;2 3  Public classChars_compare {4      Public Static voidMain (string[] args) {5 6Boolean Is_con =false ; 7System. out. println ("prompt, enter a string:");8Scanner sc =NewScanner (System.inch);9String toString =Sc.next (); //input string Ten         Char[] Any_char =Tostring.tochararray ();// . ToCharArray method: Convert a string to a string array  One          A          for(inti =0; I < any_char.length;i++){ -             if(Any_char [i] = ='A'){ -Is_con =true ; the             } -         } -          -         if(Is_con) { +System. out. println ("The string contains the letter ' A '"); -}Else { +System. out. println ("no letter ' A ' in the string"); A         } at          -     } -}

Initial knowledge java--Programming dot

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.