Results 1 to 4 of 4
  1. #1
    rokit boy is offline Member
    Join Date
    Feb 2012
    Posts
    35
    Rep Power
    0

    Default Not reading array properly and other things.

    My code:

    Java Code:
    package org.Bart.Tests.AI;
    
    import java.io.*;
    
    public class Main {
    	public static void print(String a) {
    		System.out.println(a);
    	}
    	public static void prnt(String[] a) {
    		System.out.println(a);
    	}
    	public static void main(String[] args) {
    		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    		String input;
    		String[] brain;
    		brain = new String[30000];
    		brain[0] = "Hello|Hi";
    		brain[1] = "Bye|Goodbye";
    		int currentResponse = 2;
    		try {
    			input = reader.readLine();
    			for (String thing : brain) {
    				if (thing != null) {
    					if (input != "") {
    						print (thing);
    					thing.substring(0,thing.indexOf("|") );
    					if (thing.contains(input))  {
    						print("[AI] " + thing.substring(thing.indexOf("|") + 1));
    					} else {
    						print("[AI] What does that mean? Can you give a response to this?");
    						String response = reader.readLine();
    						String aa = input + "|" + response;
    						//print (aa);
    						brain[currentResponse] = aa;
    						currentResponse++;
    						print("[AI] Thanks, I've learnt that when somebody says " + input + " then I say " + response + ".");
    					}
    					} else {
    						print ("We have a problem");
    					}
    				}
    			}
    		} catch (IOException e) {
    			print("You suck at typing");
    		}
    	}
    }
    I have some issues.
    ONE (Issue): I have clearly set brain[1] to "Bye|Goodbye" but when I print "thing" (thing is the String that goes through all the string in the array.) it only shows up in the first one.
    TWO (How can I...): How can I make it so after I type something then I will be asked for input again?
    THREE (How can I...): My learning AI works, but there a better system I can think of like a text file with responses.

    Feel free to post anything that could help me in the slightest.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: Not reading array properly and other things.

    Please post the output from the program that shows what it does when executed.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    rokit boy is offline Member
    Join Date
    Feb 2012
    Posts
    35
    Rep Power
    0

    Default Re: Not reading array properly and other things.

    Well when I type in Hello, it responses hi, as it should be.
    When I input Goodbye, my string-in-array-finder doesn't find it, though it clearly says brain[1] = "Bye|Goodbye"; in the main code, so if the AI can't find the string it goes to the else bit.

    Also, how can I do it so it asks me for input again.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: Not reading array properly and other things.

    Please post the console's contents from when you execute your program that shows what it prints out.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Reading a .txt file into an array
    By nifa98 in forum New To Java
    Replies: 4
    Last Post: 11-28-2011, 07:04 AM
  2. Reading lines into 2d array
    By uhertz in forum New To Java
    Replies: 1
    Last Post: 09-28-2011, 02:53 PM
  3. output giving null, methods not reading properly
    By csuever in forum New To Java
    Replies: 22
    Last Post: 04-01-2011, 02:13 AM
  4. Replies: 8
    Last Post: 03-31-2011, 06:09 AM
  5. Array not reading. Plz help
    By cmizer in forum New To Java
    Replies: 14
    Last Post: 02-12-2009, 12:02 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
  •