Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.dailyprogrammer;
- import java.util.Arrays;
- public class Easy14 {
- /**
- * @param args
- */
- public static void main(String[] args) {
- int[] normal = {1,2,3,4,5,6};
- System.out.println(Arrays.toString(normal));
- int[] in = arraySwitcher(normal, 2);
- System.out.println(Arrays.toString(in));
- }
- private static int[] arraySwitcher(int[] normal, int block){
- int[] reversed = new int[normal.length];
- int count=0;
- for(int i=0; i<normal.length/block; i++){
- for(int j=(i+1)*(block)-1; j>=i*block; j--){
- reversed[count] = normal[j];
- //-----printing to show how it works-----//
- String noramalPrint = Arrays.toString(normal);
- noramalPrint = noramalPrint.replaceAll(Integer.toString(normal[j]),"*");
- System.out.println(noramalPrint);
- try {
- Thread.sleep(800);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- String reversedPrint = Arrays.toString(reversed);
- reversedPrint = reversedPrint.replaceAll(Integer.toString(reversed[count]),"*");
- System.out.println(reversedPrint);
- System.out.println();
- try {
- Thread.sleep(3000);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- //increment reversed array counter
- count++;
- }
- }
- return reversed;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement