Advertisement
Guest User

Untitled

a guest
Mar 28th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.58 KB | None | 0 0
  1. import java.util.Comparator;
  2.   2 import java.util.Random;
  3.   3
  4.   4 object Main {
  5.   5   val ARRAY_SIZE = 10;
  6.   6   val STRING_SIZE = 20;
  7.   7
  8.   8   def printTable(
  9.   9     sortedStringA: Array[String],
  10.  10     sortedIntegerA: Array[Integer],
  11.  11     sortedFloatA: Array[Float],
  12.  12     sortedStringD: Array[String],
  13.  13     sortedIntegerD: Array[Integer],
  14.  14     sortedFloatD: Array[Float],
  15.  15     sortType: String
  16.  16   ): Unit = {
  17.  17     println(String.format("%n%40s%n============================================================",
  18.  18       sortType + " Ascending"));
  19.  19     print(String.format("%n%" + STRING_SIZE + "s |  %s  | %17s%n",
  20.  20       "Sorted Strings", "Sorted Integers", "Sorted Floats"));
  21.  21     for(i <- 0 until ARRAY_SIZE){
  22.  22       print(String.format("%s | %17d | %17f%n",
  23.  23         sortedStringA(i), sortedIntegerA(i), sortedFloatA(i).toString));
  24.  24     }
  25.  25     println(String.format("%n%40s%n============================================================",
  26.  26       sortType + " Descending"));
  27.  27     print(String.format("%n%" + STRING_SIZE + "s |  %s  | %17s%n",
  28.  28       "Sorted Strings", "Sorted Integers", "Sorted Floats"));
  29.  29     for(i <- 0 until ARRAY_SIZE){
  30.  30       print(String.format("%s | %17d | %17f%n",
  31.  31         sortedStringD(i), sortedIntegerD(i), sortedFloatD(i).toString));
  32.  32     }
  33.  33
  34.  34
  35.  35   }
  36.  36   def main(args: Array[String]) {
  37.  37
  38.  38     object IntegerComparator extends Comparator[Integer]{
  39.  39       override def compare(c1:Integer, c2:Integer): Int = {
  40.  40         c2.compareTo(c1);
  41.  41       }
  42.  42  }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement