그래서 내 프로그램은 사용자 입력이 회문인지 아닌지를 결정합니다. 그러나 입력에 대소 문자가 혼합되어 있으면 최종 출력은 모두 소문자가됩니다. 원래 사용자 입력을 출력하도록하려면 어떻게해야합니까?Java의 원래 문자열 인쇄
현재 : 사용자 입력 = Aa. 출력 = aa는 회문입니다.
목표 : 사용자 입력 = Aa. 출력 = Aa는 회문입니다.
import java.util.*;
public class Colonies {
static char [] string;
static int length;
private static Scanner scan;
public static void main (String[] args){
scan = new Scanner(System.in);
System.out.println("Please enter a string of characters.");
String s = scan.nextLine();
s = s.toLowerCase();
string = s.toCharArray();
length = string.length;
if (isPalindrome()){
System.out.println(s+" is a palindrome.");
}
else {
System.out.println(s+" is not a palindrome.");
}
}
public static boolean isPalindrome(){
boolean palindrome = true;
for (int c = 0; c < length/2; c++){
if(string[c] != string [length - c - 1]){
palindrome = false;
}
}
if (palindrome){
return true;
} else {
return false;
}
}
}