In this problem set, you have to ask the user to enter 10 values, then cube the elements in that entered array and in the end print out the original and final array
This question is not about printing an array, my concerns is how to cube all elements in an array. I tried doing this as shown below but I keep on getting random stuff in output?
public class arraysprob4 {
//raahul marreddy
// have user enter 10 numbers
// find and print the cube's
static Scanner console = new Scanner(System.in);
public static void main(String[]args) {
int newcube[] = new int[10];
int cube[] = new int[newcube.length];
System.out.println("Enter 10 numbers:");
for(int i = 0; i < cube.length; i++) {
cube[i] = console.nextInt();
newcube[i] = cube[i] * cube[i] * cube[i];
}
System.out.println("New Array is:" + newcube);
System.out.println("Old Array is :" + cube);
}
}