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:(nod):
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?
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
Code:
int a;
a = input.nextInt();
if(a==?)
But thats only if you want an input as an int.
if you want to use a string the you would do
Code:
String a;
a = input.next();
if (a.equals("1"))
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.
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.
Re: Java artificial Intelligence Help!!!!!
Thanks a lot @jhuber151 i wanted to use String and i got what i wanted Thanks a lot