Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By jhuber151

Thread: Java artificial Intelligence Help!!!!!

  1. #1
    saidatta123 is offline Member
    Join Date
    Jul 2012
    Posts
    3
    Rep Power
    0

    Lightbulb 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 05:24 PM.

  2. #2
    n3p3nthess is offline Member
    Join Date
    Jul 2012
    Location
    Borgloon, Belgium
    Posts
    4
    Rep Power
    0

    Default 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?

  3. #3
    jhuber151 is offline Member
    Join Date
    Jul 2012
    Posts
    55
    Rep Power
    0

    Default 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
    Java 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
    Java Code:
    String a;
    a = input.next();
    if (a.equals("1"))
    saidatta123 likes this.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default 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.

    ** This space for rent **

  5. #5
    saidatta123 is offline Member
    Join Date
    Jul 2012
    Posts
    3
    Rep Power
    0

    Default 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.

  6. #6
    saidatta123 is offline Member
    Join Date
    Jul 2012
    Posts
    3
    Rep Power
    0

    Default Re: Java artificial Intelligence Help!!!!!

    Thanks a lot @jhuber151 i wanted to use String and i got what i wanted Thanks a lot

Similar Threads

  1. Tic Tac Toe Artificial intelligence algorithm
    By eLancaster in forum New To Java
    Replies: 2
    Last Post: 05-26-2011, 12:09 AM
  2. artificial intelligence for a tank
    By newbie79 in forum New To Java
    Replies: 9
    Last Post: 12-22-2010, 05:27 PM
  3. Artificial Intelligence knowledge base in java
    By ala_mages in forum Advanced Java
    Replies: 5
    Last Post: 12-06-2010, 11:44 AM
  4. Artificial intelligence coding problems
    By MuslimCoder in forum New To Java
    Replies: 1
    Last Post: 02-26-2010, 04:30 PM

Posting Permissions

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