Results 1 to 9 of 9
  1. #1
    Pojahn_M's Avatar
    Pojahn_M is offline Senior Member
    Join Date
    Mar 2011
    Location
    Sweden
    Posts
    197
    Rep Power
    4

    Default Condition ignored.

    The "if" condition at line 22 is ignored.
    It is suppose to append the read(from the stream) character to codeToken three times(the "if" condition at line 22 make sure that happen), but instead, its ignored all the time.
    The output is like this:
    ------------
    h
    ------------
    h
    ------------
    e
    ------------
    C
    ------------
    It is suppose to look like this(but it doesnt, that's the problem):
    ------------
    ------------
    ------------
    hhe
    ------------
    ------------
    ------------
    Cd4
    Java Code:
    	public void decryptFile() throws Exception 
    	{
    		assetsLoaded ();
    		controlKey ();
    		
    		FileReader fr = new FileReader (this.filePath);
    		BufferedReader in = new BufferedReader (fr);
    		
    		FileOutputStream fo = new FileOutputStream (this.outputPath);
    		BufferedOutputStream out = new BufferedOutputStream (fo);
    
    		int binary;
    		int counter = 0;
    		String codeToken = "";
    		
    		while ((binary = in.read ()) != -1)
    		{
    			codeToken = codeToken + ((char) binary);
    			
    			System.out.println ("------------");//DEBUG
    			
    			if (counter++ > CODESPERCHAR)
    				continue;
    			
    			System.out.println (codeToken);//DEBUG
    			//out.write ((int)decrypt (codeToken));
    			codeToken = "";
    			counter = 0;
    		}
    		in.close ();
    		out.close ();
    	}

  2. #2
    joeyvitoro is offline Member
    Join Date
    Oct 2011
    Posts
    90
    Rep Power
    0

    Default Re: Condition ignored.

    Where is CODESPERCHAR defined?

  3. #3
    Pojahn_M's Avatar
    Pojahn_M is offline Senior Member
    Join Date
    Mar 2011
    Location
    Sweden
    Posts
    197
    Rep Power
    4

    Default Re: Condition ignored.

    in an other class(its a instance variable). I have initiated it to 3 in the constructor.
    Actually, I used wrong variable. I am suppose to use CODELENGTH(3) instead of CODESPERCHAR(30). I changed it, but the problem remain the same.
    CODELENGTH is also initiated in the constructor.
    Last edited by Pojahn_M; 12-05-2011 at 10:48 PM.

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Condition ignored.

    Quote Originally Posted by Pojahn_M View Post
    The "if" condition at line 22 is ignored.
    Impossible!

    If statements are never ignored. Your assumption that the if statement evaluates to true/false is incorrect. Debug your code by placing some print statements before the if to see what values the variables have.

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Condition ignored.

    Quote Originally Posted by Pojahn_M View Post
    in an other class(its a instance variable).
    Then how can you have direct access to it in this code?

  6. #6
    Pojahn_M's Avatar
    Pojahn_M is offline Senior Member
    Join Date
    Mar 2011
    Location
    Sweden
    Posts
    197
    Rep Power
    4

    Default Re: Condition ignored.

    I am pretty sure it is ignored, or eclipse is fucking up(its not the first time it fuck up).

    Java Code:
    			if (counter++ > CODELENGTH)
    			{
    				System.out.println ("I am not ignored");
    				continue;
    			}
    Not once is the message "I am not ignored" displayed.

    I have access to it because the variables access is protected and not private.

  7. #7
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Condition ignored.

    That means that the if statement is ALWAYS evaluating to false. It is NEVER ignored.

  8. #8
    Pojahn_M's Avatar
    Pojahn_M is offline Senior Member
    Join Date
    Mar 2011
    Location
    Sweden
    Posts
    197
    Rep Power
    4

    Default Re: Condition ignored.

    you woke me up. thanks(and stupid me).

  9. #9
    Pojahn_M's Avatar
    Pojahn_M is offline Senior Member
    Join Date
    Mar 2011
    Location
    Sweden
    Posts
    197
    Rep Power
    4

    Default Re: Condition ignored.

    Similar problem.
    The if statementat line 29 is always false. The block in line 30 to 33 is never executed. I cant see why.
    passwords.length is 3.

    Java Code:
    	public void scrambleFile (int... passwords) throws IOException
    	{
    		if (0 >= passwords.length)
    			throw new IllegalArgumentException ("At least one value");
    		
    		this.extension = "cry";
    		setFileName ();
    		
    		BufferedInputStream in = new BufferedInputStream (new FileInputStream (this.inputFile));
    		DataOutputStream out = new DataOutputStream (new BufferedOutputStream (new FileOutputStream (this.outputFile)));
    		
    		int number = 0;
    		int counter = 0;
    		boolean addition = (passwords[0] > 100) ? true : false;
    		
    		while ((number = in.read ()) != -1)
    		{
    			if (addition)	
    			{
    				out.writeInt ((number + passwords[counter]));
    				addition = false;
    			}				
    			else
    			{
    				out.writeInt ((number - passwords[counter]));
    				addition = true;
    			}
    			
    			if (++counter > passwords.length)	
    			{
    				System.out.println ("Increasing: " + counter);
    				continue;
    			}
    			System.out.println ("Reset");
    			counter = 0;
    		}
    		in.close ();
    		out.close ();
    	}
    The output:
    Reset
    Reset
    Reset
    Reset
    Reset
    Reset
    ...

Similar Threads

  1. Waiting on a condition
    By nephos in forum New To Java
    Replies: 9
    Last Post: 04-22-2011, 10:05 AM
  2. basic condition
    By ts96 in forum New To Java
    Replies: 1
    Last Post: 02-16-2011, 12:23 PM
  3. While loop condition
    By counterfox in forum New To Java
    Replies: 3
    Last Post: 10-10-2010, 01:14 AM
  4. IF-Condition in a String
    By lenaz in forum Advanced Java
    Replies: 1
    Last Post: 07-18-2009, 12:07 PM
  5. problem with using string in if condition
    By sireesha in forum New To Java
    Replies: 2
    Last Post: 11-20-2007, 10:40 PM

Posting Permissions

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