Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Lesson 33 Coding Activity 4
- *
- Write a method that takes an array of ints and reverses the order of the values in the array. So the array {1, 2, 3} would be changed to {3, 2, 1}.
- This method must be called reverse()and it must take an int[]parameter.
- *
- */
- import java.util.Scanner;
- class Lesson_33_Activity_Four {
- public static void reverse(int x[])
- {
- int z[] = new int[x.length];
- for (int i = 0; i < x.length; i++)
- {
- z[i] = x[i];
- }
- for (int i = 0; i < x.length; i++)
- {
- x[i] = z[z.length-(i+1)];
- }
- }
- public static void main(String[] args)
- {
- int x[] = {1,2,3};
- reverse(x);
- for (int i = 0; i < x.length; i++)
- System.out.print(x[i] + " ");
- }
- }
Add Comment
Please, Sign In to add comment