Java program for judging palindrome statements (variable parameters, string converted to char array)

Source: Internet
Author: User

static void Huiwen (char ... cs) {//char ... CS supports variable parameter format for

(type name ...) Variable name)--parameter list, equivalent to a variable length dynamic array, the system according to user needs to determine the length of the array
int b_ool=1;

for (int i=0;i<cs.length/2;i++)//length is the length of this variable array, note that at this time the length is an array of the following table plus 1, by cs.length-i-1
if (Cs[i]!=cs[cs.length-i-1//judgment
]){
B_ool=0;break;}

if (b_ool==1)
Joptionpane.showmessagedialog (NULL,
"You entered a palindrome statement!" ");
Else
Joptionpane.showmessagedialog (NULL,
"You are not typing a palindrome statement!" ");
}

public static void Main (string[] args) {
String Enterchar=joptionpane.showinputdialog (NULL,
"Please enter a statement:");

Char[] Ca=enterchar.tochararray (); Convert string to char array
Huiwen (CA); Call
}

Java program for judging palindrome statements (variable parameters, string converted to char array)

Related Article

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.