Question: I have to handle some strings, I should put them **N** positions to left to organize the string.

Here's my code for while:

```
private String toLeft() {
    String word = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // Example
    byte lpad = 2; // Example
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < word.length(); i++) {
        sb.append((char) (word.charAt(i) - lpad));
    }
    return sb.toString();
}

```

It's working for inputs that don't have to move many times...

So, the problem is that when the number N of positions to move is a little bit large (like 10), it returns me non letters, like in the example below, what can I do to prevent it?

Ex.: `ABCDEFGHIJKLMNOPQRSTUVWXYZ` if I move each char 10 positions to left it returns `789:;<=>?@ABCDEFGHIJKLMNOP` while it must return `QRSTUVWXYZABCDEFGHIJKLMNOP`.

### Some inputs and their expected outputs:

* `VQREQFGT // 2 positions to left == TOPCODER`
* `ABCDEFGHIJKLMNOPQRSTUVWXYZ // 10 positions to left == QRSTUVWXYZABCDEFGHIJKLMNOP`
* `LIPPSASVPH // 4 positions to left == HELLOWORLD`

Answer: 
I think you have misunderstood what your (homework?) requirements are asking you to do. Lets look at your examples:

> 
> VQREQFGT // 2 positions to left == TOPCODER
> 
> 
> 

Makes sense. Each character in the output is two characters before the corresponding input. But read on ...

> 
> ABCDEFGHIJKLMNOPQRSTUVWXYZ // 10 positions to left == QRSTUVWXYZABCDEFGHIJKLMNOP
> 
> 
> 

Makes no sense (literally). The letter `Q` is not 10 characters before `A` in the alphabet. There is no letter in the alphabet that is before `A` in the alphabet.

OK so how do you get from `A` to `Q` in 10 steps? 

Answer ... you wrap around!

`A`, `Z`, `Y`, `X`, `W`, `V`, `U`, `T`, `S`, `R`, `Q` ... 10 steps: count them.

So what the requirement is actually asking for is N characters to the left *with wrap around*. Even if they don't state this clearly, it is the only way that the examples "work".

But you just implemented N characters to the left *without* wrap around. You need to implement the wrap around. (I won't show you how, but there lots of ways to do it.)

---

There's another thing. The title of the question says "Decrement only letters" ... which implies to me that your requirement is saying that characters that are not letters should not be decremented. However, in your code you are decrementing *every* character in the input, whether or not it is a letter. (The fix is simple ... and you should work it out for yourself.)
> 
> what can I do to prevent it?
> 
> 
> 

You make it wrap around.  

If you want a value to go from 10 to 19 and then start at 10 again, in each iteration you subtract 10, increase by one, take the remainder of that divided by 20, and add 10 again.

Only here, 10 is `'A'`, 19 is `Z`, and instead of increasing by one, we add or subtract n.

```
private String toLeft() {
    String word = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // Example
    byte lpad = 10; // Example
    StringBuilder sb = new StringBuilder();
    int n = -lpad;                  // I'm using n here to I can use '+ n' below
    for (int i = 0; i < word.length(); i++) {
        int shifted = word.charAt(i) - 'A' + n;
        shifted %= ('Z' - 'A' + 1); // This is for positive n
        while(shifted < 0)          // And this for negative ones
        {
            shifted += ('Z' - 'A' + 1);
        }
        sb.append((char)(shifted + 'A'));
    }
    return sb.toString();
}

```