Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi i need help with a code to removes all duplicates words and all words that ar

ID: 3547690 • Letter: H

Question

                    Hi i need help with a code to removes all duplicates words and all words that are less than 8 characters in length and remove any leading or trailing white                     space and also remove the last word . Example                 

                

                    input file:                 

                

                    
                

                

                    about adv
                    about prep
                    above adv
                    above rep
                    absence n
                    absolutely adv
                    academic adj
                    accept n
                    access v
                

                

                    
                

                

                    output file:                 

                

                    
                

                

                    absolutely                 

                

                    academic
                

                                     

Explanation / Answer


import java.io.*;

import java.util.*;


public class SampleTest {


public static void main(String[] args) throws IOException {

Set<String> arr = new HashSet<String>();

Scanner inScanner = new Scanner(new File("input.txt"));

while (inScanner.hasNext()) {

String str = inScanner.nextLine();

String word= str.trim();

if(word.length() < 8) {

continue;

}

arr.add(word);

}


BufferedWriter writer = new BufferedWriter(new FileWriter(new File("output.txt")));

for(int i=0;i<arr.size()-1;i++) {

writer.write(arr[i]+" ");

}

writer.close();




}


}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote