public static String showResults(int num) throws Exception {

        FileOutputStream outputStream = new FileOutputStream(OUTPUT_FILE);
        PrintStream outputFileWriter = new PrintStream(outputStream);

        Set<String> keys = words.keySet();
        ArrayList<WordFreqPair> rankedWords = new ArrayList<WordFreqPair>(keys.size());

        for(String key : keys) {
            int freq = words.get(key);
            WordFreqPair pair = new WordFreqPair(key, freq);
            rankedWords.add(pair);
        }

        Collections.sort(rankedWords);

        int numToShow = Math.min(num, rankedWords.size());
        int mostWords = calcMost(rankedWords);

        int sumOfRankedWordsUpper = 0;
        int sumOfRankedWordsLower = 0;
        int upperLimit;
        int lowerLimit;

        // detailed analysis. Use this in future use cases
        for(int i = 0; i < numToShow; i++) {

            int predicted = (int) (1.0 / (i + 1) * mostWords);
            int actual = rankedWords.get(i).freq;
            double error = 100.0 * (predicted - actual) / predicted;

            String result = "rank: " + (i + 1) + " " + rankedWords.get(i)
                    + ", predicted: " + predicted + " error: " + error;
       }

        //upper limit for Ziph's formula on arbitrary basis
        for(int i = 0; i < numToShow/2; i++)
            sumOfRankedWordsUpper = sumOfRankedWordsUpper + rankedWords.get(i).freq;

        upperLimit = sumOfRankedWordsUpper/(numToShow/2);

        //lower limit for Ziph's formula on arbitrary basis
        for(int i = numToShow/2; i < numToShow; i++ )
            sumOfRankedWordsLower = sumOfRankedWordsLower + rankedWords.get(i).freq;

        lowerLimit = sumOfRankedWordsLower/(numToShow/2);

        //extracting the words between these limits

        String combinedOutput = "";

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

            int frequency = rankedWords.get(i).freq;

            if(frequency<=upperLimit && frequency>=lowerLimit) {

                WordFreqPair keyValuePair = rankedWords.get(i);
                String pair = keyValuePair.toString();

                combinedOutput += pair.split(" ")[0];
                combinedOutput += " ";

                outputFileWriter.print(pair.split(" ")[0]);
                outputFileWriter.print(" ");
            }
        }

        return combinedOutput;
    }