Results 1 to 15 of 15
  1. #1
    tnd_blazer is offline Member
    Join Date
    Jun 2013
    Posts
    12
    Blog Entries
    1
    Rep Power
    0

    Question What am i doing wrong!?

    i don't get it.... i can't get the thing to read and know what you typed... and respond to the input. Please help

    Java Code:
    import java.util.Scanner;
    public class ab {
    	public static void ask1(String args[]){
    		System.out.println("Welcome to the ask program, Today i wll ask you everything. Lets begin");
    		Scanner user_input = new Scanner( System.in );
    		String first_name;
    		first_name = user_input.next( );
    		System.out.println(first_name);
    		if(first_name == "Hello"){
    			System.out.println("Hello there!");
    		}
    	}
    }
    Last edited by tnd_blazer; 06-11-2013 at 04:19 AM.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: What am i doing wrong!?


  3. #3
    tnd_blazer is offline Member
    Join Date
    Jun 2013
    Posts
    12
    Blog Entries
    1
    Rep Power
    0

    Default Re: What am i doing wrong!?

    what are the code tags...
    Thanks though, the program has no main method becus im makeing it with multie classes

  4. #4
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: What am i doing wrong!?

    Quote Originally Posted by tnd_blazer View Post
    what are the code tags...
    Java Programming Forum - Learn Java Programming - New Syntax Highlighter

    Thanks though, the program has no main method becus im makeing it with multie classes
    You failed to mention this - which is why we always recommend posting an Short, Self Contained, Correct Example to remove guessing from the equation. And to reach the widest audience, I do recommend posting in proper English grammar, its hard enough for a native English speaker to understand that sentence let alone non-native speakers.

  5. #5
    bigsonny is offline Senior Member
    Join Date
    Nov 2010
    Posts
    164
    Rep Power
    4

    Default Re: What am i doing wrong!?

    tnd, can you state plainly what you are trying to accomplish?

  6. #6
    tnd_blazer is offline Member
    Join Date
    Jun 2013
    Posts
    12
    Blog Entries
    1
    Rep Power
    0

    Default Re: What am i doing wrong!?

    Quote Originally Posted by doWhile View Post
    Java Programming Forum - Learn Java Programming - New Syntax Highlighter



    You failed to mention this - which is why we always recommend posting an Short, Self Contained, Correct Example to remove guessing from the equation. And to reach the widest audience, I do recommend posting in proper English grammar, its hard enough for a native English speaker to understand that sentence let alone non-native speakers.
    Sorry for the fail on english. and other things. but i can keep that in mind. thanks for your time

  7. #7
    tnd_blazer is offline Member
    Join Date
    Jun 2013
    Posts
    12
    Blog Entries
    1
    Rep Power
    0

    Default Re: What am i doing wrong!?

    Quote Originally Posted by bigsonny View Post
    tnd, can you state plainly what you are trying to accomplish?
    If you type "Hello" I want it to be able to read that and respond to it buy printing "Hello there" so that latter on i can get it to say act like a console and perform commands. Basicly if i asked you, were do you live. Then you would say were you live back. Thats what i want it to do. And im sorry for not posting it to stand buy it's self. here is the code after i fixed it up.

    Java Code:
    import java.util.Scanner;
    public class ab {
    	public static void ask1(String args[]){
    		System.out.println("Welcome to the ask program, Today i wll ask you everything. Lets begin");
    		Scanner user_input = new Scanner( System.in );
    		String first_name;
    		first_name = user_input.next( );
    		System.out.println(first_name);
    		if(first_name == "Hello"){
    			System.out.println("Hello there!");
    		}
    	}
    }

  8. #8
    tnd_blazer is offline Member
    Join Date
    Jun 2013
    Posts
    12
    Blog Entries
    1
    Rep Power
    0

    Default Re: What am i doing wrong!?

    again thanks for taking the time to help me with my posting skills, Im new here COMPLETELY new to java so... thanks a lot for you help and ill try to improve my spelling and grammar skills.

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: What am i doing wrong!?

    Quote Originally Posted by tnd_blazer View Post
    What am i doing wrong!?
    Please go through the Forum Rules, particularly the third paragraph.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  10. #10
    bigsonny is offline Senior Member
    Join Date
    Nov 2010
    Posts
    164
    Rep Power
    4

    Default Re: What am i doing wrong!?

    Quote Originally Posted by tnd_blazer View Post
    If you type "Hello" I want it to be able to read that and respond to it buy printing "Hello there" so that latter on i can get it to say act like a console and perform commands. Basicly if i asked you, were do you live. Then you would say were you live back. Thats what i want it to do. And im sorry for not posting it to stand buy it's self. here is the code after i fixed it up.

    Java Code:
    import java.util.Scanner;
    public class ab {
    	public static void ask1(String args[]){
    		System.out.println("Welcome to the ask program, Today i wll ask you everything. Lets begin");
    		Scanner user_input = new Scanner( System.in );
    		String first_name;
    		first_name = user_input.next( );
    		System.out.println(first_name);
    		if(first_name == "Hello"){
    			System.out.println("Hello there!");
    		}
    	}
    }
    OKay, I think you're trying to do too much with this one method but before that there are some fundamental issues with your understanding of the way a class is structured.

    If this class doesn't contain your main method, it is most likely going to be the class where you write your methods. As such, you should following the basic rules for doing so:

    The basic one is that your method should probably have a constructor though it's not mandatory.

    Your method should be simple. It should do one thing, not ten things. Currently, your method welcomes the user and then waits for the an input but doesn't ask a question and then prints the first_name variable with println which will sent you to the next line. There is a lot to fix.

  11. #11
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,514
    Rep Power
    5

    Default Re: What am i doing wrong!?

    After you get the overall syntax of a runnable class fixed try replacing
    Java Code:
    if(first_name == "Hello"){
        System.out.println("Hello there!");
    }
    with
    Java Code:
    if(first_name.equals("Hello")){ 
         System.out.println("Hello there!");
    }
    You should not compare strings using ==. That only checks for object equality, not object state equality.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  12. #12
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: What am i doing wrong!?

    Quote Originally Posted by bigsonny View Post
    The basic one is that your method should probably have a constructor though it's not mandatory.
    Huh?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  13. #13
    bigsonny is offline Senior Member
    Join Date
    Nov 2010
    Posts
    164
    Rep Power
    4

    Default Re: What am i doing wrong!?

    I meant the class he wrote, not the method.

    Quote Originally Posted by DarrylBurke View Post
    Huh?

    db

  14. #14
    tnd_blazer is offline Member
    Join Date
    Jun 2013
    Posts
    12
    Blog Entries
    1
    Rep Power
    0

    Default Re: What am i doing wrong!?

    Thank you very mutch Jim! that helped a lot! now i can go on with my program. Thank you!

  15. #15
    tnd_blazer is offline Member
    Join Date
    Jun 2013
    Posts
    12
    Blog Entries
    1
    Rep Power
    0

    Default Re: What am i doing wrong!?

    Quote Originally Posted by tnd_blazer View Post
    i don't get it.... i can't get the thing to read and know what you typed... and respond to the input. Please help

    Java Code:
    import java.util.Scanner;
    public class ab {
    	public static void ask1(String args[]){
    		System.out.println("Welcome to the ask program, Today i wll ask you everything. Lets begin");
    		Scanner user_input = new Scanner( System.in );
    		String first_name;
    		first_name = user_input.next( );
    		System.out.println(first_name);
    		if(first_name.equals("Hello")){
         System.out.println("Hello there!");
    }
    	}
    }
    Thanks to Jim, This is now fixed ^.^

Similar Threads

  1. Replies: 4
    Last Post: 06-11-2013, 01:37 AM
  2. I can't find anything wrong with this but somehow it's wrong.
    By Biscuit Tickler in forum New To Java
    Replies: 2
    Last Post: 09-12-2012, 09:28 PM
  3. What am I doing wrong?
    By PhilK in forum New To Java
    Replies: 7
    Last Post: 04-15-2012, 08:22 PM
  4. What Am I doing Wrong?
    By siren1111 in forum New To Java
    Replies: 3
    Last Post: 12-20-2011, 02:01 AM
  5. What did i do wrong
    By jpnym15 in forum New To Java
    Replies: 8
    Last Post: 11-17-2008, 10:07 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
  •