# CodingBat: Java. String-1, Part I

In the String-1 section on CodingBat you have the chance to familiarize yourself with basic string operations. The exercises do get a bit repetitive, but you should be able to quickly go through all of them and move on to more challenging parts.

All solutions were successfully tested on 19 January 2013.

helloName:

```public String helloName(String name) {
return "Hello " + name + "!";
}
```

makeAbba:

```public String makeAbba(String a, String b) {
return a + b + b + a;
}
```

makeTags:

```public String makeTags(String tag, String word) {
return "<" + tag + ">" + word + "</" + tag + ">";
}
```

makeOutWord:

```public String makeOutWord(String out, String word) {
return out.substring(0,2) + word + out.substring(2);
}
```

extraEnd:

```public String extraEnd(String str) {
int len = str.length();
return str.substring(len - 2) + str.substring(len - 2)
+ str.substring(len - 2);
}
```

firstTwo:

```public String firstTwo(String str) {
if (str.length() < 2) return str;
return str.substring(0, 2);
}
```

firstHalf:

```public String firstHalf(String str) {
return str.substring(0, str.length()/2);
}
```

withoutEnd:

```public String withoutEnd(String str) {
return str.substring(1, str.length() - 1);
}
```

comboString:

```public String comboString(String a, String b) {
if (a.length() > b.length()) return b + a + b;
return a + b + a;
}
```

nonStart:

```public String nonStart(String a, String b) {
return a.substring(1) + b.substring(1);
}
```

## 2 thoughts on “CodingBat: Java. String-1, Part I”

1. Pingback: Work | namfam