This is my code .. When I am compiling it it says sarr is an undeclared variable...please help me sort this problem out.
import java.util.*;
public class StringPractise2 {
public static void main() {
String temp;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the sentence:");
String s = sc.nextLine();
s = s.toUpperCase();
int l = s.length();
int c; //String sarr[];
if (s.charAt(l - 1) == '@' || s.charAt(l - 1) == '.') {
StringTokenizer str = new StringTokenizer(s, "@.");
c = str.countTokens();
String sarr[] = new String[c];
for (int i = 0; i < c; i++)
sarr[i] = str.nextToken();
for (int i = 0; i < c; i++) {
for (int j = i + 1; j < c; j++) {
if (sarr[i].compareTo(sarr[j]) > 0) {
temp = sarr[i];
sarr[i] = sarr[j];
sarr[j] = temp;
}
}
}
}
System.out.println("The original sentence:" + s);
System.out.println("The array is alphabetical order:");
for (int i = 0; i < c; i++) {
System.out.println(sarr[i] + " ");
}
}
}