I can't seem to figure out how to separate the code I wrote into 3 separate methods.
1. The main method, 2. the method that creates the strings i need and sends em back to the main method, 3. and the method that displays the if statement.
import java.io.*;
import java.util.StringTokenizer;
public class Super2
{
public static void main(String[] args) throws IOException //main method
{
String number;
StringTokenizer st;
StringBuffer first, middle, last; // 3 separate number groups
StringBuffer phonenumber = new StringBuffer();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter phone number using the (xxx) xxx-xxxx format: ");
number = br.readLine();
st = new StringTokenizer(number, " (), -"); //takes out symbols & spaces
first = new StringBuffer(st.nextToken());
middle = new StringBuffer(st.nextToken());
last = new StringBuffer(st.nextToken());
//combine 3 string buffers
phonenumber = phonenumber.append(first).append(middle).append(last);
String str = phonenumber.toString();
System.out.println(str);
String reverse = phonenumber.reverse().toString();
//if statement for comparing reverse
if (str.equals(reverse))
System.out.println("The number is a palindrome");
else
System.out.println(str + "is not equal to" + reverse);
}
}
Could anyone help me create the 2 other classes? I'm not sure how to send the data down to the other two methods..I've tried a few different things, but failed miserably every time