Results 1 to 3 of 3

Thread: logic error?

  1. #1
    droidus is offline Senior Member
    Join Date
    Feb 2011
    Posts
    244
    Rep Power
    4

    Default logic error?

    i need help doin some logic here:

    Java Code:
    // put each part of text into an array (task name, task content, task
    		// priority)
    		for (int i = 0; i < originalLine.length(); i++) {
    			if (originalLine.charAt(i) != '' && originalLine.charAt(i) != '') {
    				text = text + originalLine.charAt(i);
    			} else if (originalLine.charAt(i) == '' || start == true) {
    				elements[counter] = text;
    				counter++;
    				text = "";
    				start = false;
    			} else if (originalLine.charAt(i) == '') {
    				System.out.println("Counter: " + counter + "\ni: " + i);
    				break;
    			} else {
    				break;
    			}
    		}
    		System.out.println("1: " + elements[0] + " 2: " +  elements[1] + " 3: " +  elements[2]);
    output:

    Java Code:
    1: task1 2: text 3: null
    input:

    Java Code:
    task1text2
    should put out:

    Java Code:
    1: task1 2: text 3: 2
    thanks.

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: logic error?

    ? you are only printing the counter state, you have to add
    else if (originalLine.charAt(i) == '') {
    elements[counter] = text; // <-----
    break;
    }
    ??
    And why do you dont use the split method? Or Pattern and Matcher class!
    Java Code:
    		String originalLine  = "task1text2";
    		Matcher m = Pattern.compile("(.+)(.+)(\\d)").matcher(originalLine);
    		if(m.find()){
    			System.out.println(m.group(1)+" "+m.group(2)+" "+m.group(3));
    		}
    thats all!

  3. #3
    droidus is offline Senior Member
    Join Date
    Feb 2011
    Posts
    244
    Rep Power
    4

    Default Re: logic error?

    oh, makes sense! :p
    and thanks for this! didn't even know about that method!

Similar Threads

  1. Logic Error using loop and array
    By janey4115 in forum New To Java
    Replies: 1
    Last Post: 11-17-2011, 06:24 PM
  2. Need help in logic
    By nn12 in forum New To Java
    Replies: 3
    Last Post: 03-23-2011, 06:44 PM
  3. help with a logic error
    By ShinTec in forum Advanced Java
    Replies: 11
    Last Post: 05-02-2010, 10:19 PM
  4. Logic Error: simulated accuracy
    By Kaito in forum New To Java
    Replies: 3
    Last Post: 10-27-2009, 01:39 PM
  5. Logic Error: Not Writing To File
    By JDCAce in forum Advanced Java
    Replies: 6
    Last Post: 10-21-2008, 02:13 AM

Posting Permissions

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