Results 1 to 4 of 4
- 03-18-2012, 07:49 AM #1
Member
- Join Date
- Feb 2012
- Posts
- 35
- Rep Power
- 0
Not reading array properly and other things.
My code:
I have some issues.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"); } } }
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.
- 03-18-2012, 01:34 PM #2
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.
- 03-18-2012, 03:11 PM #3
Member
- Join Date
- Feb 2012
- Posts
- 35
- Rep Power
- 0
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.
- 03-18-2012, 03:56 PM #4
Similar Threads
-
Reading a .txt file into an array
By nifa98 in forum New To JavaReplies: 4Last Post: 11-28-2011, 07:04 AM -
Reading lines into 2d array
By uhertz in forum New To JavaReplies: 1Last Post: 09-28-2011, 02:53 PM -
output giving null, methods not reading properly
By csuever in forum New To JavaReplies: 22Last Post: 04-01-2011, 02:13 AM -
Please help on nullpointerexception error.. Cannot initallize the array properly.
By tvenhc in forum New To JavaReplies: 8Last Post: 03-31-2011, 06:09 AM -
Array not reading. Plz help
By cmizer in forum New To JavaReplies: 14Last Post: 02-12-2009, 12:02 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks