Help
I am comparing strings and having trouble with my code. Here are my errors and my code is below.
Strings.java:42: ')' expected
System.out.println(s1 " comes before " s2);
^
Strings.java:42: not a statement
System.out.println(s1 " comes before " s2);
^
Strings.java:42: ';' expected
System.out.println(s1 " comes before " s2);
^
Strings.java:44: ')' expected
System.out.println(s1 " follows " s2);
^
Strings.java:44: not a statement
System.out.println(s1 " follows " s2);
^
Strings.java:44: ';' expected
System.out.println(s1 " follows " s2);
^
Strings.java:49: reached end of file while parsing
}
[publicclass Strings
{
publicstaticvoid main(String[] args)
{
String s1, s2;
Scanner scan =new Scanner (System.in);
System.out.println("Enter the first string:");
s1 = scan.nextLine();
System.out.println("Enter the second string:");
s2 = scan.nextLine();
//Sting length of the characters
System.out.println("String Length of s1: " + s1.length());
System.out.println("String Length of s2: " + s2.length());
//Compare the characters
char ch1, ch2;
for (int i = 0; (i < s1.length()) || (i < s2.length()); i++){
ch1 = s1.charAt(i);
ch2 = s2.charAt(i);
if(ch1 < ch2){
System.out.print(s1 +" comes before " + s2);
return;
}
if (ch1 > ch2){
System.out.print(s1 +" follow " + s2);
return;
}
if (s1.length()< s2.length()){
System.out.println(s1" comes before " s2);
}elseif (s1.length() > s2.length()){
System.out.println(s1" follows " s2);
}else{
System.out.println("The names are the same");
}
}
}

