You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1.5 KiB

SortArgs

Instructions

Create a file named SortArgs.java.

Write a function sort that sorts the given array specified in the parameters and print the sorted array into the standard ouput. The elements should be separated by spaces with a new line at the end. All the given elements are correct numbers.

Expected Functions

public class SortArgs {
    public static void sort(String[] args) {
        // your code here
    }
}

Usage

Here is a possible ExerciseRunner.java to test your function :

import java.io.*;

public class ExerciseRunner {
    public static void main(String[] args) throws IOException {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        PrintStream printStream = new PrintStream(outputStream);
        System.setOut(printStream);
        SortArgs.sort(new String[]{"4","2","1","3"});
        String output = outputStream.toString();
        System.out.println(output.equals("1 2 3 4\n"));
    }
}

and its output :

$ javac *.java -d build
$ java -cp build ExerciseRunner
true
$

Notions

Command-Line Arguments Conditional statement String Array File