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

Thread: How do i store input from the keyboard into a method?

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How do i store input from the keyboard into a method?

    Hey guys and girls, just like the title says, how do i store keyboard input into a method? (OOP) So i have two classes, BankAccount, and Tester. My constructor and methods are in BankAccount and my Tester class has code that asks for keyboard input. I know how to store numbers into them if i do it straight from my code, but how do i store keyboard input into a variable, more specifically doubles.

    Sorry if i confused everyone, which i probably did, but if anyone could help that would be great


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,300
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: How do i store input from the keyboard into a method?

    how do i store keyboard input into a method
    You could use one of the Scanner class's methods to read the input into a variable.
    Look at the API doc for the Scanner class and/or do a Search here on the forum for sample code.

    If that is not your problem, please explain.
    Variables local to a method go away when the method exits, so you can not use local variables to store data. To have the data be available to more than one method, you would need to use a class variable.

  3. #3
    Member Emperor_Xyn's Avatar
    Join Date
    Dec 2011
    Posts
    66
    My Mood
    Devilish
    Thanks
    21
    Thanked 2 Times in 2 Posts

    Default Re: How do i store input from the keyboard into a method?

    If I know what you mean go line.

    yourclass uc= new yourclass();
    Initialise scanner
    string name=keyboard.next();
    uc.urmethodtoinsert(name);

Similar Threads

  1. Multilingual keyboard input
    By yep in forum Java Theory & Questions
    Replies: 1
    Last Post: November 12th, 2011, 02:23 AM
  2. Replies: 3
    Last Post: October 31st, 2011, 01:42 AM
  3. Replies: 2
    Last Post: April 21st, 2011, 11:29 AM
  4. Help with making the user input to store in file
    By dannyyy in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 6th, 2011, 07:52 AM
  5. Input method
    By RyanToast in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 2nd, 2011, 06:07 PM