New To Java - null
I need some help count all the character in a string. When I run my program it only count the first string. Thanks.
Here is my code
publicclass Strings
{
publicstaticvoid main(String[] args)
{
String s1;
String 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("Sting Length of s1: " + s1.length());
System.out.println("Sting Length of s2: " + s2.length());
//Compare the characters
char ch1 = s1.charAt(0);
char ch2 = s2.charAt(0);
for (int count = 0; count < 1; count++){
if(ch1 < ch2)
System.out.print(s1 +" comes before " + s2);
if (s1.equals(s2))
System.out.println("The names are the same.");
else
System.out.print(s1 +" follows " + s2);
}
}
}
[1996 byte] By [
tmlucky13a] at [2007-11-26 23:14:08]

I really don't know I had a hard figuring this out. I need it to count string 1 and then count string 2 and then compare them using the CharAt. I know that I need to change something in this part of the code, but I don't know what.
for ( int count = 0; count < 1; count++) {if(ch1 < ch2)
System.out.print(s1 + " comes before " + s2);
if (s1.equals(s2))
System.out.println("The names are the same.");
else
System.out.print(s1 + " follows " + s2);
Also I might be wrong here (probably the case) but to me it seems that your logic isnt quite right either. If you had 2 strings:
String str1 = "Hallo";;String str2 = "Hello";
Then both chars would be 'H'. So the first condition isnt met, the strings are not equal either so the second conditions isnt met, which means it defaults to your final condition. But this would say that str1 comes after str2 alphabetically, which isnt actually true.
Sorry if Im wrong and just confused you...