1.
/**
 * 
 * Problem #10327 - Flip Sort
 * Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=15&page=show_problem&problem=1268

 * 
 * @author Mariya Vlaseva
 * 
 * Status : Accepted
 * Runtime: 0.672
 */
import java.util.Scanner;

public class Main {

private static final int MAX_NUMBERS_SIZE = 1000;

/**
* @param args
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String result = "";
while(sc.hasNext()) {
int size = sc.nextInt();
if(checkInput(size)) {
int[] numbers = new int[size];
for(int i = 0; i < size; i++) {
numbers[i] = sc.nextInt();
}
result += bubbleSort(numbers) + " ";
}
}
sc.close();
printResult(result.trim());
}

private static void printResult(String result) {
for(String s : result.split(" ")) {
System.out.println("Minimum exchange operations : " + s);
}
}

private static int bubbleSort(int[] numbers) {
int exOps = 0;
boolean swap = true;
while(swap) {
swap = false;
for(int i = 0; i < numbers.length; i++) {
if(i+1 < numbers.length && numbers[i] > numbers[i+1]) {
int tmp = numbers[i];
numbers[i] = numbers[i+1];
numbers[i+1] = tmp;
exOps++;
swap = true;
}
}
}
return exOps;
}

private static boolean checkInput(int size) {
return size > 0 && size <= MAX_NUMBERS_SIZE;
}
}

2.

/**

* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10

 * Problem: 10327 - Flip Sort

* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=15&page=show_problem&problem=1268

*

 * @author Viktoriya Ryabova

* @version 1.0, 05/22/2010

*

 * Method : Ad-Hoc

* Status : Accepted

* Runtime: 0.624

*/

 

import java.util.Scanner;

public class Main {

 

     

      public static void main(String[] args) {

            // TODO Auto-generated method stub

            Scanner sc = new Scanner (System.in);

            while (sc.hasNext()) {

 

                  int count = sc.nextInt();

                  if (count<=1000){

                  int[] numbers = new int[count];

                  //zahlen werden aus der kosnole in das array hinzugefuegt

                  for (int i = 0; i < count; i++) {

                        numbers[i] = sc.nextInt();

                  }

                  int swaps = sortiere(numbers);

                  System.out.println("Minimum exchange operations : "+swaps);

                  }

            }

      }

      public static int sortiere(int[] x) {

            int swaps = 0;

            boolean unsortiert=true;

            int temp;

           

            while (unsortiert){

               unsortiert = false;

               for (int i=0; i < x.length-1; i++)

                   //neben stehende zahlen werden verglichen

                   //falls vorgehende zahl groesser ist, als nachkommende, werden die getauscht und

                   // count nach oben gezaehlt

                  if (x[i] > x[i+1]) {                     

                     temp       = x[i];

                     x[i]       = x[i+1];

                     x[i+1]     = temp;

                     swaps++;

                     unsortiert = true;

                  }         

            }

            return swaps;

      }

}