I am having trouble with an output for my code and cant understand why I am getting this output. The problem is: "Given an array of n elements and an integer k, 0 < k ≤ n, design and implement an algorithm that shifts the array to the left by k positions and “wraps around” any elements that “fall” from the front of the array to the back of the array. The algorithm can use O(n) time and O(n) space, where n is the number of elements in the input array."
import java.util.Scanner;
public class ShiftingArrayElements{
public static void main(String [] args) {
int x = 0;
int j=0;
Scanner sc = new Scanner(System.in);
String data = sc.nextLine();
x = sc.nextInt();
String tmpDataArray[] = data.split(" ");
int dataArray[] = new int[tmpDataArray.length];
for (int i = 0; i < dataArray.length; ++i) {
dataArray[i] = Integer.parseInt(tmpDataArray[i]);
}
if(x > dataArray.length)
x = x%dataArray.length;
int result[] = new int[dataArray.length];
for(int i=0; i < x; i++){
result[i] = dataArray[dataArray.length-x+i];
}
for(int i=x; i<dataArray.length; i++){
result[i] = dataArray[j];
j++;
}
System.out.print("Output:" + result + " ");
System.arraycopy( result, 0, dataArray, 0, dataArray.length );
sc.close();
}
}
My Input should look like this:
3 4 5 19 10
2
My output should look like this:
Output: 5 19 10 3 4
My output when I run it is:
Output:[I@42a57993