아래 코드는 숫자를 두 번 입력하도록 요청합니다.사용자 입력이 두 번 묻습니다
public class Palindrome {
public static void main(String[] args) {
boolean x;
boolean display;
x = check();
display = display();
}
private static int getUserInput() {
int inputNumber = 0;
String answer = JOptionPane.showInputDialog(null, "Please enter a five digit number","Enter a number");
inputNumber = Integer.parseInt(answer);
return inputNumber;
}
private static boolean check(){
int inputNumber = getUserInput();
int number = inputNumber;
int[] myArray = new int[5];
for (int i = 0; i < myArray.length; i++) {
myArray[i] = (int) (number /(Math.pow(10,i)) % 10);
}
if(myArray[0] == myArray[4] && myArray[1] == myArray[3])
return true;
else
return false;
}
public static boolean display(){
if (check() == true) {
JOptionPane.showMessageDialog(null, "This number is a Palindrome",
"Excellent!",
JOptionPane.INFORMATION_MESSAGE);
} else
JOptionPane.showMessageDialog(null,
"Number is not a Palindrome!",
"Sorry",
JOptionPane.ERROR_MESSAGE);
return false;
}
}
한 번만 물어보고 싶습니다.
감사
관련없는 메모에서'display' 메서드 내에서 'else' 블록에 중괄호가 없습니다. –