#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    3
    Rep Power
    0

    Basic java method question


    Hi all, need some help as im a bit confused. Ive been assigned a bit of coursework. im doing ok understanding methods etc but im stuck and confused on another bit.

    Method1 is simply a prompt requesting the users name. so ive used:
    class module {
    static String name;
    static Scanner keyboard = new Scanner(System.in);

    static void myName(){ // Method whoAmi
    System.out.println("Please enter your first name \t"); // Name prompt
    name = keyboard.next(); // Keyboard input relating to String name
    } // End
    }

    Does this look ok?, the static before the method look ok?.

    Next question is (this is where im confused),
    i must create a method and give it a name()
    it asks to take as a parameter String and returns a single character. it should contain a code that prompts user to input a integer.

    I'm assuming this would by keyboard.nextInt ()

    Would the parameter value go in the name(value here)
    Would i create the char and String outside the method?

    Sorry if this is confusing, but i can explain better to reply's.
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    3
    Rep Power
    0
    those links dont help at all as Ive read them before. i dont use objects,i know how to name a method. any research i do throws up objects.

    can anybody help me with my question
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    i dont use objects
    How do you write java code without using objects? The O in OOP stands for object.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    3
    Rep Power
    0
    Originally Posted by NormR
    How do you write java code without using objects? The O in OOP stands for object.
    at this early stage we are just to use simple code.

    I just need to understand how to bring in a string and output a char.

    String HELLO
    eg, i ask user to make selection.

    If user inputs int "3"

    Output would be "L"
  10. #6
  11. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    Use a String class method to get a single letter out of a String. Read the API doc for the String class to find one that would work.

IMN logo majestic logo threadwatch logo seochat tools logo