Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Whats wrong?

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Whats wrong?

    [code]/**
    *
    */

    /**
    * @author Andrewbacon
    *
    */
    import static java.lang.System.out;
    import static java.lang.System.*;
    import java.util.Scanner;

    public class game {

    /**
    * @param args
    */
    public static void main(String[] args) {
    System.out.println("Welcome,Player,to 0verload.");
    System.out.println("Type your name,player");
    for ( {
    out.print(">");

    Scanner keyboard = new Scanner(System.in);
    String input = keyboard.next();
    String playername = "Player";

    String input = input;

    out.println("Welcome" + input);
    }




    }


    }[code/]
    Last edited by help2; June 2nd, 2012 at 09:47 PM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Whats wrong?

    You tell us what's wrong...does it compile? Are there exceptions? Does it misbehave? Please read the link in my signature entitled 'getting help', and please wrap your code in the code tags

  3. #3
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Whats wrong?

    for ( {
    out.print(">")
    That doesn't seem valid to me.

    String input = keyboard.next();
    String playername = "Player";

    String input = input;

    It isn't a good idea to have the same variable name "input".

    Change one of them to "input2" otherwise you'll probably get an error saying that input was already defined.

    You don't, I don't think you do anyway, have a class variable called "out". I think you're looking for

    System.out.println("Welcome " + input);

    Also, if you're looking for a full name, then use nextLine() instead of next(). next() goes till it finds a space.

    A for loop goes like this:


    for (variable_type variable = some_value; variable < someOtherValue; variable++)

    or that's one of the ways it could go.

    If you want to print out n ">" then you could

    for (int i =0; i < n; i++)
    {
    System.out.println(">");
    }
    Last edited by javapenguin; June 2nd, 2012 at 11:59 PM.

  4. #4
    Junior Member
    Join Date
    May 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Whats wrong?

    String input = input; // is not acceptable because... input variable is already there...

    it gives compile error......at this point ....

    if we change String input1 = input;System.out.println(""+output1);

    the code will run fine output is ===

    Welcome,Player,to 0verload.
    Type your name,player
    > //cursour waits here for user input ... if u give input like uname...than output
    Welcomeuname


    modified code

    import static java.lang.System.out;
    import static java.lang.System.*;
    import java.util.Scanner;

    public class game {
    public static void main(String[] args) {
    System.out.println("Welcome,Player,to 0verload.");
    System.out.println("Type your name,player");
    for ({
    out.print(">");
    Scanner keyboard = new Scanner(System.in);
    String input = keyboard.next();
    String playername = "Player";
    String input1 = input;
    out.println("Welcome " + input1);
    }
    }
    }


    note :: playername variable is neverused ... and .. unused import system.lang

Similar Threads

  1. Whats wrong here?
    By Java Sucks in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 8th, 2011, 08:33 PM
  2. whats wrong?
    By whattheeff in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 25th, 2011, 02:35 PM
  3. whats wrong with this one....
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: October 6th, 2009, 10:08 AM
  4. help whats wrong
    By silverspoon34 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 3rd, 2009, 01:41 AM
  5. [SOLVED] whats wrong with my IDE
    By chronoz13 in forum Java IDEs
    Replies: 2
    Last Post: August 27th, 2009, 06:34 AM