String variables also have an inherited function called "equals" which takes another string to compare against. It returns a boolean value which you can then store in your bool1. Here is your project modified...
java
public class Assign7
{
public static void main(String[] args)
{
String s1 = "George ";
String s2 = "Meghabghab";
String s3 = s1.concat(s2);
String s4 = s2.substring(2, 6);
String s5 = s2.substring(0,2);
String s6 = s5.concat(s4).concat(s4);
// equals function of a string returns a boolean
boolean bool1 = s2.equals(s6);
// If true, print they are the same.
if (bool1) { System.out.println("Yes s2 and s6 are equal"); }
String s7 = s1.substring(0,1).concat(s2.substring(0,1));
System.out.println(s3);
System.out.println(s4);
System.out.println(s5);
System.out.println(s6);
System.out.println(s7);
}
}
That should explain it all. Enjoy!
"At DIC we be string comparing and equalizing code ninjas!"
This post has been edited by Martyr2: 17 Mar, 2008 - 01:52 PM