Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String conCat(String a, String b) {
- String str;
- if(a.length()==0 | b.length()==0){
- str = a+b;
- }
- else if(a.substring(a.length()-1, a.length()) == (b.substring(0,1))){
- str = a + b.substring(2,b.length());
- }
- else{
- str =a+b;
- }
- return str;
- }
- public class conCat {
- /* public String a;
- public String b;*/
- /* public conCat(String str1, String str2){
- a = str1;
- b = str2;
- }*/
- /* public String getA(){
- return a;
- }
- public String getB(){
- return b;
- }*/
- public String conCat2(String a, String b) {
- String str="";
- if(a.length() ==0 | b.length() ==0){
- str=a+b;
- }
- else{
- if(a.substring(a.length()-1, a.length()).equals(b.substring(0,1))){
- str = a + b.substring(1, b.length());
- }
- else{
- str=a+b;
- }
- }
- return str;
- }
- }
- public class main {
- public static void main(String[] args){
- conCat[] result = new conCat[6];
- result[0] = new conCat2("abc", "cat");
- result[1] = new conCat2("dog", "cat");
- result[2] = new conCat2("abc", "");
- result[3] = new conCat2("", "cat");
- result[4] = new conCat2("pig", "g");
- result[5] = new conCat2("pig", "doggy");
- conCat our = new conCat();
- String outs = our.conCat2("abc", "cat");
- System.out.println(outs);
- /*
- for(conCat e: result){
- result.conCat2(e.getA(), e.getB());
- }*/
- }
- }
Add Comment
Please, Sign In to add comment