Can someone tell me why does my code not work?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2

Thread: Can someone tell me why does my code not work?

Hybrid View

  1. #1
    Join Date
    Mar 2013

    Exclamation Can someone tell me why does my code not work?

    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?
    import javax.swing.JOptionPane;
    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);
    			cont = false;
    				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){
    					finished= true;
    					cont = true;

  2. #2
    Join Date
    Jun 2011
    .NET4.0 / VS 2010

    Re: Can someone tell me why does my code not work?

    What is your code failing to do? I see you have created a FileWriter and PrintWriter but never used either to save into the file. Read up on how FileWriter and PrintWriter work since I am guessing your issue is that the file has nothing saved into it.

    Essentially what you want to do is
    1. Ask user for word
    2. If valid input > Save word to file || Else if invalid input take appropriate measures.
    3. When finished adding words into the dictionary and outside the loop close the writer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a survey!

HTML5 Development Center