New To Java - Need some help
I change my code to the way my teacher wanted it, but still have a little trouble. I am having trouble with my program counting all the character in the string. Like if I typed (tanned) in string1 and (tanning) in string2 it would print tanned follows tanning when it suspose to be tanned comes before tanning. Also having trouble getting it to equal to each other (print tanning is equal to tanning or print the two strings are equal). Can somebody please help me finish this program. Thanks
Here is my code below
[code][import java.util.Scanner;
public class Strings
{
public static void 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(1);
char ch2 = s2.charAt(1);
for ( int count = 0; count < 1; count++) {
if(ch1 < ch2)
System.out.print(s1 + " comes before " + s2);
else
System.out.print(s1 + " follows " + s2);
}
}
}[code]
[1384 byte] By [
tmlucky13a] at [2007-11-26 23:08:19]

Sorry About my Code
I change my code to the way my teacher wanted it, but still have a little trouble. I am having trouble with my program counting all the character in the string. Like if I typed (tanned) in string1 and (tanning) in string2 it would print tanned follows tanning when it suspose to be tanned comes before tanning. Also having trouble getting it to equal to each other (print tanning is equal to tanning or print the two strings are equal). Can somebody please help me finish this program. Thanks
Here is my code below
import java.util.Scanner;
public class Strings
{
public static void 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(1);
char ch2 = s2.charAt(1);
for ( int count = 0; count < 1; count++) {
if(ch1 < ch2)
System.out.print(s1 + " comes before " + s2);
else
System.out.print(s1 + " follows " + s2);
}
}
}
Like if I typed (tanned) in string1 and (tanning) in
string2 it would print tanned follows tanning when it
suspose to be tanned comes before tanning.
Yes because you compare the first character of each string and in this case both strings start with 't' and 't' is not less than 't' so you always hit the else statement.
>for ( int count = 0; count < 1; count++) {<div class="jive-quote">
<b>if(ch1 < ch2)</b>
System.out.print(s1 + " comes before " + s2);
else
System.out.print(s1 + " follows " + s2);
}
}
}