Tuesday, January 11, 2011

JAVA BAT : String 1 : makeAbba

In String 1 section of Java Bat there are basic string problems in which you cannot use loops to solve the problem. We should use string functions like str.length(),  str.substring(i, j) etc.

Make ABBA Problem: Given two strings, a and b, return the result of putting them together in the order abba.
Examples:
makeAbba("Hi", "Bye") → "HiByeByeHi"
makeAbba("Yo", "Alice") → "YoAliceAliceYo"
makeAbba("x", "y") → "xyyx"

In this problem a method that has two string as parameter for example string A and B should return a string that is in the order ABBA. For example 'Hi' and 'Bye' are passed as parameter then the result should be 'HiByeByeHi'.

Answer For this Java Bat problem:


                   public String makeAbba(String a, String b) {
                                      String str=a+b+b+a;
                                      return
str;
                   }
 
  
Above Code can also be written in this way:


                   public String helloName(String a, String b) {

                                          
 return a+b+b+a;

                   }

   
 

No comments:

Post a Comment