My code is supposed to take in words from the end user and store them in a file called dictionary, one word at a time. But t doesn't do so. Can someone tell me why?
Code:import javax.swing.JOptionPane; import java.io.*; import java.util.*; public class RoughWork { public static void main(String[]args) throws IOException { String maxWords = "", minWords = ""; int maxLength=0, minLength=2000; String input = "", aWord=""; boolean cont,finished = false; FileWriter aFileWriter = new FileWriter("Dictionary.txt"); PrintWriter out = new PrintWriter(aFileWriter); while(!finished) { cont = false; while(!cont) { input = JOptionPane.showInputDialog(null,"Please enter the word you'd like to add to the dictionary: "); if(input.contains(" ") || input.matches(".*\\d.*") ||input == ""){ JOptionPane.showMessageDialog(null,"Please enter one word only!"); cont = false; } else if( input == null){ cont=true; finished= true; } else cont = true; } } out.println(input); } }




Reply With Quote