전화 번호를 뒤집고 모든 구분 기호를 제거하고 원래 번호와 비교하여 그것이 회문인지 확인하는 프로그램을 작성 중입니다. 또한 전화 번호를 쉼표로 정수로 변환합니다. 몇 가지 문제가 있습니다. 나는 오류가 발생하고 이유를 모릅니다. 또한 번호가 회문인지 아닌지를 정확하게 판별하지 않습니다. 어떤 도움을 주시면 감사하겠습니다.문자열 토큰 화기 및 버퍼 사용 방법.
//Phone String Palindrome Conversions
//This program will turn a phone number around and check to see if it is a palindrome
//This program will remove all deasdspace and symbols from the phone number
//This program will reverse the string and compare it to the original
//This program will put a phone number in a long intiger format
import java.io.*;
import java.util.*;
import java.text.DecimalFormat;
public class DottinoN_palindrome
{
public static void main (String [] args) throws IOException
{
String phoneshort1;
boolean pal;
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter your phone number");
String phone1=br.readLine();
phoneshort1 = spaceremover(phone1);
System.out.println(phoneshort1);
pal = palindrometest(phoneshort1);
System.out.println(pal);
if(pal = false)
{
System.out.println("Your phone number is a palindrome!");
}
else if(pal = true)
System.out.println("Your phone number is not a palendrome...");
numberformat(phoneshort1);
}
public static String spaceremover (String phone2)
{
String phoneshort = "";
StringTokenizer st = new StringTokenizer(phone2,"()- " ,false);
while(st.hasMoreTokens())
{
phoneshort += st.nextToken();
}
return phoneshort;
}
public static boolean palindrometest (String phoneshort2)
{
boolean pal;
StringBuffer br = new StringBuffer(phoneshort2);
String phonebkwd = br.reverse().toString();
if(phonebkwd == phoneshort2)
{
pal = true;
}
else pal = false;
System.out.println(phonebkwd + "--" + phoneshort2);
return pal;
}
public static void numberformat (String phoneshort2)
{
DecimalFormat formatter = new DecimalFormat("0,000,000,000");
int number = Integer.parseInt(phoneshort2);
System.out.println("Your phone number as an intiger is: " + formatter.format(number));
}
}
적절한 답을 표시하십시오. – wipindipy10