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)