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 9 of 9

Thread: I was just about to start and it has problems?

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default I was just about to start and it has problems?

    [java] im using eclipse luna and it auto terminates as soon as it starts it just terminates?
    import java.util.Scanner;
    public class data {
    public static void main(String args[]){
    Scanner input = new Scanner (System.in);
    }
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: I was just about to start and it has problems?

    What would you expect it to do?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Jul 2014
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: I was just about to start and it has problems?

    I was just gonna make something where you type in a word and it tells you what it means but all im trying to do is test the scanner and it doesn't even do that

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: I was just about to start and it has problems?

    How are you testing a Scanner?

    All this code does is create a Scanner. You don't actually tell the Scanner to do anything, and you don't print anything to the console, which is why you don't see anything when the program executes.

    Try adding a simple print statement at the very end of your main() method, that way you at least know it's running.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Junior Member
    Join Date
    Jul 2014
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: I was just about to start and it has problems?

    the text appears but it just skips right over the scanner and prints it
    import java.util.Scanner;
    public class data {
    public static void main(String args[]){
    Scanner input = new Scanner (System.in);
    System.out.println("hello world");
    }
    }

  6. #6
    Junior Member
    Join Date
    May 2013
    Location
    Charleston SC
    Posts
    21
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default Re: I was just about to start and it has problems?

    Scanner is just an object. You haven't called any of its methods to have it do anything.

  7. #7
    Junior Member
    Join Date
    Jul 2014
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: I was just about to start and it has problems?

    ive used this line before and it let me type in but its not this time literally just Scanner input = new Scanner(system.in); and it let me type in

  8. #8
    Junior Member
    Join Date
    May 2013
    Location
    Charleston SC
    Posts
    21
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default Re: I was just about to start and it has problems?

    Try something like

    String s= input.next();
    System.out.println(s);

    after your hello world print statement

    Check out the API http://docs.oracle.com/javase/7/docs...l/Scanner.html

  9. The Following User Says Thank You to jbarke12 For This Useful Post:

    blockmaster2001 (October 1st, 2014)

  10. #9
    Junior Member
    Join Date
    Jul 2014
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: I was just about to start and it has problems?

    that's incredible thanks jbarke12

Similar Threads

  1. Where should I start
    By Stomper in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 9th, 2014, 07:29 AM
  2. how do i start
    By leolyte in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 18th, 2013, 07:20 AM
  3. How to start
    By ashwinjava in forum Member Introductions
    Replies: 2
    Last Post: January 29th, 2012, 04:03 PM
  4. Where do i start?
    By cejay in forum Java Theory & Questions
    Replies: 9
    Last Post: September 10th, 2011, 04:21 PM
  5. Where to start?
    By tonykasdorf in forum Java Theory & Questions
    Replies: 3
    Last Post: March 4th, 2010, 11:52 PM

Tags for this Thread