Results 1 to 4 of 4

Thread: help needed.

  1. #1
    dirtycash is offline Member
    Join Date
    Nov 2007
    Posts
    38
    Rep Power
    0

    Default help needed.

    problem solved.
    Last edited by dirtycash; 12-03-2007 at 11:15 PM.

  2. #2
    dirtycash is offline Member
    Join Date
    Nov 2007
    Posts
    38
    Rep Power
    0

    Default

    Java Code:
    Scanner in=new Scanner(System.in); //scanner object to get input from keyboard later
    
    CODEpublic String getText(String prompt)
    {
    System.out.println(prompt);
    System.out.println("Enter word/email");
    //make a string called b and in it put whatever the user inputs
    String b=in.nextLine();
    return (b);
    }
    
    ---------------------
    
    CODEpublic int getNumber(String prompt)
    {
    System.out.println(prompt);
    System.out.println("Enter integEr");
    int LOL=in.nextInt();
    return (LOL);
    }
    does this code answer the questions a and b properly?
    it does compile but i dont think it works.

  3. #3
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    If you just want the two methods you can write and use them like this.
    Java Code:
    import java.io.*;
    
    public class ExpTest
    {
        Scanner in=new Scanner(System.in);
    
        public static void main(String[] args)
        {
            ExpTest test = new ExpTest();
            System.out.println(test.getText("Enter word/email"));
            System.out.println(test.getNumber("Enter integEr"));
        }
    
        private String getText(String prompt)
        {
            System.out.println(prompt);
            //make a string called b and in it put whatever the user inputs
            // Save user input in variable "b" and return it to the caller.
            String b=in.nextLine();
            return b;
        }
    
        private int getNumber(String prompt)
        {
            System.out.println(prompt);
            int LOL=in.nextInt();
            return LOL;
        }
    }
    If you want to encapsulate them in a separate class you would make a few changes.

  4. #4
    dirtycash is offline Member
    Join Date
    Nov 2007
    Posts
    38
    Rep Power
    0

    Default

    problem solved.
    Last edited by dirtycash; 12-03-2007 at 11:15 PM.

Similar Threads

  1. help needed!!! :S
    By mark-mlt in forum Networking
    Replies: 1
    Last Post: 04-14-2008, 10:27 AM
  2. Help needed.
    By necro-1000 in forum AWT / Swing
    Replies: 2
    Last Post: 01-12-2008, 12:37 PM
  3. Help Needed
    By pks in forum New To Java
    Replies: 1
    Last Post: 01-09-2008, 01:07 AM
  4. Uni Project - GUI - Help Needed
    By deeadeed in forum New To Java
    Replies: 0
    Last Post: 12-04-2007, 12:10 AM
  5. jfreeReport help needed
    By sandor in forum XML
    Replies: 1
    Last Post: 04-20-2007, 09:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •