Results 1 to 2 of 2
  1. #1
    JordiLaForge is offline Member
    Join Date
    Apr 2013
    Posts
    5
    Rep Power
    0

    Exclamation Complicated for loop's and array checking

    Hello,

    I am trying to make a user input intrerupator by spliting inputed text into a array, then checking text files that have words in them, and seeing if any match.
    So far it works if the keyword is only one word, but if I have a combination of sentences it just get's confusing.
    Java Code:
    public class checkText {
        
        static String[] inputMethod , stringConstruct;
        
        static int iteration;
        
        static boolean checkText;
    
    
        public static boolean main( String filePath , String[] userInput ){
    	
    	inputMethod = inputLoad.main ( filePath , "inputMethod" );
    	
    	checkText = false;
    	
    	iteration = 0;
    
    	for ( int x = 0 ; x <= userInput.length - 1 ; x = x + 1 ){
    	    
    		for ( int y = 0 ; y < inputMethod.length ; y = y + 1 ){
    		    
    		    stringConstruct = new String[ inputMethod[ y ].split( " " ).length ];
    		    
    		    for ( int z = 0 ; z <=  inputMethod[ y ].split( " " ).length ; z = z + 1 ){
    
    			if ( userInput[ x ].equals( inputMethod[ y ] ) ){
    			
    			    checkText = true;
    			
    			}
    			else{
    			    
    			    if ( x + 1 < userInput.length & z + 1 <= inputMethod[ y ].split( " " ).length ){
    			
    				if ( userInput[ x ].equals( inputMethod[ z ] ) & userInput[ x + 1 ].equals( inputMethod[ z + 1 ] ) ){
    				    
    				    checkText = true;
    				    
    				}
    				
    			    }
    			    
    			}
    			
    		    }
    		    
    		}
    		
    	}
    	
    	return checkText;
    	
        }
        
    }
    The trouble come's around line 34, and if someone could help me make this more efficient with for loop's that would be really great :D

  2. #2
    monkeyjr97 is offline Senior Member
    Join Date
    Nov 2012
    Posts
    258
    Rep Power
    3

    Default Re: Complicated for loop's and array checking

    you need to use && to signify and, not just &, also wrap each argument in brackets

    ((argument 1) && (argument 2))

Similar Threads

  1. Replies: 2
    Last Post: 09-25-2012, 12:31 AM
  2. Checking if a value only apears once in an array
    By Domenatrice in forum New To Java
    Replies: 1
    Last Post: 12-20-2011, 01:46 AM
  3. Replies: 1
    Last Post: 11-13-2011, 12:25 PM
  4. Checking to see if Array is sorted
    By pytho in forum New To Java
    Replies: 5
    Last Post: 07-06-2011, 02:39 AM
  5. Replies: 5
    Last Post: 03-19-2010, 01:26 AM

Tags for this Thread

Posting Permissions

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