Java Regular Expressions

Source: Internet
Author: User

Used to keep track of what's going on in actual programming and keep updating.

Such as:

Develop a coordinate calculation tool, a for moving to the left, D for moving to the right, W for moving up, and s for moving down. Moves from the (0,0) point, reads some coordinates from the input string, and outputs the final input to the output file. Input: The legal coordinates are a (or D or W or s) + number (within two digits), and the coordinates are separated by; Illegal coordinate points need to be discarded.  such as AA10;  A1A;  $%$; YAD; such as

ImportJava.util.*;ImportJava.util.regex.Matcher;ImportJava.util.regex.Pattern; Public classMain { Public Static voidMain (string[] args) {Scanner Scanner=NewScanner (system.in);  while(Scanner.hasnext ()) {String input=Scanner.next (); String[] Arr= Input.split (";"); String pattern= "[adws][0-9]{1,2}"; Pattern R=Pattern.compile (Pattern); List<String> list =NewArraylist<string>();  for(inti=0;i<arr.length;i++) {Matcher m=R.matcher (Arr[i]); //The find () method is a partial match//matches () is the full match                if(M.matches ()) {List.add (M.group ()); }                        }            intX=0, y=0;  for(intI=0;i<list.size (); i++)            {                CharDirection = List.get (i). CharAt (0); intLen = integer.valueof (List.get (i). SUBSTRING (1)); //System.out.println (len);                Switch(direction) { Case' A ': X-=Len;  Break;  Case' D ': x + =Len;  Break;  Case' W ': y + =Len;  Break;  Case' S ': y-=Len;  Break; default:                     Break; }} System.out.println (x+","+y);    } scanner.close (); }}

Java Regular Expressions

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.