Q:

Output of caesar shift reversed

I'm trying to implement a simple caesar shift using java:
import java.util.Scanner;

public class Caesar_shift {
public static String message;
public static String Shift_msg;

public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    System.out.print("Please type message: ");
    message = scanner.next();
    setShift_msg(message);
    System.out.println(Shift_msg);
}

public static String setShift_msg(String msg) {
    String valueOf;
    for (int i = 0, n = msg.length(); i < n; i++) {
        char c = msg.charAt(i);
        c = (char) (c + 1);
        valueOf = String.valueOf(c);
        Shift_msg = valueOf += Shift_msg;
    }
    return Shift_msg;
}

}
When I run my program,
String message = "abc"
I should get the output bcd. However, it returns "dcbnull".
How could I fix it, and also why does this happen?

A:

Change the line Shift_msg = valueOf += Shift_msg; to Shift_msg += valueOf;
That explains why it was reversed. And to get rid of the null at the end, set Shift_msg = ""; either at the beginning of the method or when at the string declaration.

