Test input (i tried starting/ending with >6 and <7 still works as should be):
hi what is up longerthansix waylongerthansix short goodday 666666 7777777
output:
longerthansix,waylongerthansix,goodday,7777777
not sure whats wrong here do you spot it?
thanks!
package com.codegym.task.task19.task1925;
/*
Long words
*/
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class Solution {
public static void main(String[] args) throws IOException {
FileReader in = new FileReader(args[0]);
FileWriter out = new FileWriter(args[1]);
StringBuilder sb = new StringBuilder();
while (in.ready()){
sb.append((char)in.read());
}
in.close();
String[] words = sb.toString().split(" "); //String of words
String txt = "";
for(String word : words){ // check length and add if >6
if(word.length() > 6){
txt += word + ",";
}
}
out.write(txt.substring(0,txt.length()-1)); //write data except last char
out.close();
}
}