Results 1 to 6 of 6
- 07-26-2012, 04:21 PM #1
Member
- Join Date
- Jul 2012
- Posts
- 3
- Rep Power
- 0
Java artificial Intelligence Help!!!!!
What should i use so that i can give an input as - "Hi" with java.util.scanner - and i get back the output - Hi wassup or somthing like that - with if else. Can i use char if so please help. I am new to java.
Here is my code:-
import java.util.Scanner;
class qwerty
{
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
Char a; //Can i use char?
System.out.println("Hi!");
a = input.nextInt();
if (a == )//What should i do here?If i use Char?
{
System.out.println("Wassup?");
}
else {
System.out.println("Sorry. I cant understand you.");
}
}
}
Thanks
Last edited by saidatta123; 07-26-2012 at 04:24 PM.
- 07-26-2012, 04:39 PM #2
Member
- Join Date
- Jul 2012
- Location
- Borgloon, Belgium
- Posts
- 4
- Rep Power
- 0
Re: Java artificial Intelligence Help!!!!!
I dont' really get what you are trying to do.
Can you give an example of the input/output you are trying to achieve?
- 07-26-2012, 04:43 PM #3
Member
- Join Date
- Jul 2012
- Posts
- 55
- Rep Power
- 0
Re: Java artificial Intelligence Help!!!!!
What would you like the input to be. In this case you are getting an int so you should use
But thats only if you want an input as an int.Java Code:int a; a = input.nextInt(); if(a==?)
if you want to use a string the you would do
Java Code:String a; a = input.next(); if (a.equals("1"))
- 07-26-2012, 04:44 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: Java artificial Intelligence Help!!!!!
Please use [code] tags [/code] when posting code.
This is the API for Scanner.
In there you'll find the nextLine() method.
That'll give you a String, which is what you are expecting the user to input.Please do not ask for code as refusal often offends.
- 07-28-2012, 07:12 AM #5
Member
- Join Date
- Jul 2012
- Posts
- 3
- Rep Power
- 0
Re: Java artificial Intelligence Help!!!!!
First the computer prints "Hi!" on the screen. Then I would want to type "Hi" the computer replys as Wassup.
- 07-28-2012, 07:15 AM #6
Member
- Join Date
- Jul 2012
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Tic Tac Toe Artificial intelligence algorithm
By eLancaster in forum New To JavaReplies: 2Last Post: 05-25-2011, 11:09 PM -
artificial intelligence for a tank
By newbie79 in forum New To JavaReplies: 9Last Post: 12-22-2010, 04:27 PM -
Artificial Intelligence knowledge base in java
By ala_mages in forum Advanced JavaReplies: 5Last Post: 12-06-2010, 10:44 AM -
Artificial intelligence coding problems
By MuslimCoder in forum New To JavaReplies: 1Last Post: 02-26-2010, 03:30 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks