How to split a string into a character array in Java

Source: Internet
Author: User

Title: Enter a string of characters, made up of () {}[], to determine if all the parentheses are closed brackets, yes returns true, not return false.

/* Input string, disassembled as a character array
* Use function S.charat (i) to complete
*
* */
Import java.util.*;
Import java.lang.*;
public class Char {
public static void Main (string[] args) {
String A=new string ();
Scanner in=new Scanner (system.in);
A=in.next ();
Char[]b=new char[100];
Boolean bool=true;
for (int i=0;i<a.length (); i++) {
B[i]=a.charat (i);
}
for (int i=0;i<a.length (); i++) The length of the {///array. length; lengths of strings. Length ()
if (b[i]== (' {')) {//char is the base type, this cannot be used with equals ()
if (b[i+1]== '} ')
Continue
else{
Bool=false;
Break
}
}

if (b[i]== ' (') {
if (b[i+1]== ') ')
Continue
else{
Bool=false;
Break
}
}

if (b[i]== ' [') {
if (b[i+1]== '] ') {
Continue
}
else{
Bool=false;
Break
}
}
Bool=true;
}
if (bool==true)
System.out.println ("True");
Else
System.out.println ("False");
}
}

How to split a string into a character array in Java

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.