Advertisement
Guest User

Untitled

a guest
Feb 28th, 2012
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. package com.dailyprogrammer;
  2.  
  3. import java.util.Arrays;
  4.  
  5. public class Easy14 {
  6.  
  7.     /**
  8.      * @param args
  9.      */
  10.     public static void main(String[] args) {
  11.         int[] normal = {1,2,3,4,5,6};
  12.         System.out.println(Arrays.toString(normal));
  13.         int[] in = arraySwitcher(normal, 2);
  14.         System.out.println(Arrays.toString(in));
  15.  
  16.     }
  17.    
  18.     private static int[] arraySwitcher(int[] normal, int block){
  19.         int[] reversed = new int[normal.length];
  20.         int count=0;
  21.        
  22.         for(int i=0; i<normal.length/block; i++){
  23.             for(int j=(i+1)*(block)-1; j>=i*block; j--){
  24.                
  25.                 reversed[count] = normal[j];
  26.                
  27.                 //-----printing to show how it works-----//
  28.                 String noramalPrint = Arrays.toString(normal);
  29.                 noramalPrint = noramalPrint.replaceAll(Integer.toString(normal[j]),"*");
  30.                 System.out.println(noramalPrint);
  31.                 try {
  32.                     Thread.sleep(800);
  33.                 } catch (InterruptedException e) {
  34.                     // TODO Auto-generated catch block
  35.                     e.printStackTrace();
  36.                 }
  37.                 String reversedPrint = Arrays.toString(reversed);
  38.                 reversedPrint = reversedPrint.replaceAll(Integer.toString(reversed[count]),"*");
  39.                 System.out.println(reversedPrint);
  40.                 System.out.println();
  41.                 try {
  42.                     Thread.sleep(3000);
  43.                 } catch (InterruptedException e) {
  44.                     // TODO Auto-generated catch block
  45.                     e.printStackTrace();
  46.                 }
  47.                
  48.                 //increment reversed array counter
  49.                 count++;
  50.                
  51.             }
  52.            
  53.         }
  54.        
  55.         return reversed;
  56.     }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement