Guest User

Untitled

a guest
Jan 16th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. public String conCat(String a, String b) {
  2. String str;
  3. if(a.length()==0 | b.length()==0){
  4. str = a+b;
  5. }
  6. else if(a.substring(a.length()-1, a.length()) == (b.substring(0,1))){
  7. str = a + b.substring(2,b.length());
  8. }
  9. else{
  10. str =a+b;
  11. }
  12. return str;
  13. }
  14.  
  15. public class conCat {
  16. /* public String a;
  17. public String b;*/
  18.  
  19. /* public conCat(String str1, String str2){
  20. a = str1;
  21. b = str2;
  22. }*/
  23.  
  24. /* public String getA(){
  25. return a;
  26. }
  27.  
  28. public String getB(){
  29. return b;
  30. }*/
  31.  
  32. public String conCat2(String a, String b) {
  33. String str="";
  34. if(a.length() ==0 | b.length() ==0){
  35. str=a+b;
  36. }
  37. else{
  38. if(a.substring(a.length()-1, a.length()).equals(b.substring(0,1))){
  39. str = a + b.substring(1, b.length());
  40. }
  41. else{
  42. str=a+b;
  43. }
  44. }
  45.  
  46. return str;
  47. }
  48. }
  49.  
  50.  
  51. public class main {
  52.  
  53. public static void main(String[] args){
  54. conCat[] result = new conCat[6];
  55. result[0] = new conCat2("abc", "cat");
  56. result[1] = new conCat2("dog", "cat");
  57. result[2] = new conCat2("abc", "");
  58. result[3] = new conCat2("", "cat");
  59. result[4] = new conCat2("pig", "g");
  60. result[5] = new conCat2("pig", "doggy");
  61.  
  62. conCat our = new conCat();
  63. String outs = our.conCat2("abc", "cat");
  64. System.out.println(outs);
  65. /*
  66. for(conCat e: result){
  67. result.conCat2(e.getA(), e.getB());
  68. }*/
  69.  
  70. }
  71.  
  72.  
  73. }
Add Comment
Please, Sign In to add comment