Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class upr12 {
- public static void main(String[] args) {
- int [] array = {2,3,6,7,88,3,1};
- int [] array2 = {2,4,6,6,18,9,51};
- System.out.println(Arrays.toString(array));
- reverseArr(array);
- System.out.println(Arrays.toString(array));
- System.out.println(check1(array));
- System.out.println(check1(array2));
- }
- public static void reverseArr(int[] array) {
- for(int i = 0; i < array.length / 2 ; i++ ) {
- int I = array[i];
- array [i] = array [array.length - 1 -i];
- array [array.length - 1 - i] = I;
- }
- }
- public static void printReverseArr(int[] array) {
- for(int i = array.length - 1 ; i>= 0; i--) {
- System.out.print(array[i] + " ");
- }
- System.out.println();
- }
- public static boolean check1(int[] array) {
- boolean check = true;
- for (int i = 0; i<array.length /2; i++) {
- if(array[i] != array[array.length - 1 - i]) {
- check = false;
- break;
- }
- }
- return check;
- }
- public static void check2(int[] array) {
- boolean check = true;
- for (int i = 0; i<array.length /2; i++) {
- if(array[i] != array[array.length - 1 - i]) {
- check = false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement