CodilityTest2_Exception - gopichandnishad/Codility GitHub Wiki

class Solution { public static void main(String[] args) { int[] A = {3, 8, 9, 7, 6}; int K = 3; int[] results = solution(A, K); for (Integer result : results){ System.out.println("Array is : " + result); } }

public static int[] solution(int[] A, int K) {
	BufferedReader reader = null;

	try {
		for (int i = 1; i <= K; i++) {

			int lastElement = A[A.length - 1];
			for (int pos = A.length - 2; pos >= 0; pos--) {
				A[pos + 1] = A[pos];
			}
			A[0] = lastElement;
		}

	} catch (Exception e) {
		System.out.println(e.getMessage());
	} finally {
		try {
			if (reader != null) {
				reader.close();
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}
	return A;
}

}