Help with a question on strings... just 1 part.

Help with a question on strings... just 1 part.




i got this question in a computer science lab which i couldn't complete and even though it doesnt count now i would really like to know the solution.. the exact question is



" Write a Java program that creates two Strings of the same length. Your program should check

to see if the Strings are equal length and print an appropriate message to the screen. Your

program should, if the strings are equal length, print out alternative letters from each string.

For example, it should print the first letter from the first string, the second letter from the

second string, the third letter from the first string, the fourth letter from the second string,

and so on. For example, if the first string is Hello World and the second string is World Hello

the output should be: Hollo Werld "



i wrote

public static void main(String args[])

{

//intitalise the words you want the length of

String s = "Hello";

String t = "World";

int length1 = s.length();

int length2 = t.length();



if (length1==length2)

{

//message to be printed if words are equal in length

System.out.println("The words " +s + " and "+ t + " have the same amount of letters");

}

else if (length1 > length2)

{

//words to be printed if string s is bigger than string t

System.out.println("The word " + s + " is bigger than the word " + t);

}

else

{

//words to be printed if string t is bigger than string t

System.out.println("The word " + t + " is bigger than the word " + s);

}



}

}



for the 1st part but im not sure how to do the seccond part .. ie. changing the 1st letter of the 1st string, 2nd letter of the 2nd string etc !





No Answers Posted Yet.