Java tutorial
//package com.java2s; public class Main { /** * * @param input * @param newDigit * @return */ public static String formatInput(String input, int newDigit) { String output = input + Integer.toString(newDigit); int start = output.length() - 4; if (start < 0) { start = 0; } String format = output.substring(start, output.length()); return format; } }