Page 1 of 2 12 LastLast
Results 1 to 20 of 24
  1. #1
    str4kt is offline Member
    Join Date
    Oct 2008
    Posts
    9
    Rep Power
    0

    Default Need help~~~ Midterm tomorrow!!!

    I have my first midterm tomm (Intro to Comp Science)...


    I'm having a hard time with this problem, (It's on the review sheet I received) and was wondering if anyone could help me out.

    1. Implement a method named replace that will ask the user to enter their first name.
    The method will then print (to the screen) the name with the last letter replaced with a dollar sign.

    If the name is Jack the output will be Jac$

    This may be easy to some of you experts, but realize I'm new at this..

    Thanks.

  2. #2
    gnarly hogie is offline Member
    Join Date
    Oct 2008
    Posts
    34
    Rep Power
    0

    Default

    Go search through the String API's on Suns website you will find it.

  3. #3
    str4kt is offline Member
    Join Date
    Oct 2008
    Posts
    9
    Rep Power
    0

    Default

    Huh? Whats the mean >_>...

    I don't even know how to start off with this problem..

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    to really learn this, you must attempt this first. So in that light, let's see your attempt. Then we can go over any points of misunderstanding.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by str4kt View Post
    I don't even know how to start off with this problem..
    Then it's time to talk to your teacher.

  6. #6
    str4kt is offline Member
    Join Date
    Oct 2008
    Posts
    9
    Rep Power
    0

    Default

    How do i implement a method... I usually started off with...

    public static void main(String[] args)


    Do i start off with that same line?

  7. #7
    gnarly hogie is offline Member
    Join Date
    Oct 2008
    Posts
    34
    Rep Power
    0

    Default

    Quote Originally Posted by str4kt View Post
    Huh? Whats the mean >_>...

    I don't even know how to start off with this problem..
    Did your teacher tell you about API's?

  8. #8
    str4kt is offline Member
    Join Date
    Oct 2008
    Posts
    9
    Rep Power
    0

    Default

    Nope he hasn't.

  9. #9
    gnarly hogie is offline Member
    Join Date
    Oct 2008
    Posts
    34
    Rep Power
    0

    Default

    Is your trouble with finding the method to do that or implementing a method?

  10. #10
    str4kt is offline Member
    Join Date
    Oct 2008
    Posts
    9
    Rep Power
    0

    Default

    Well it says insert a method named "replace"... How would I do that?

  11. #11
    gnarly hogie is offline Member
    Join Date
    Oct 2008
    Posts
    34
    Rep Power
    0

    Default

    Well for replace you would do something like this
    variable.replace('character you want to replace' , 'character you will replace with');

    eg. Smack.replace('m' , 'l');

  12. #12
    gnarly hogie is offline Member
    Join Date
    Oct 2008
    Posts
    34
    Rep Power
    0

    Default

    Oh and most methods if not all are something like that you just need to know the parameters

  13. #13
    str4kt is offline Member
    Join Date
    Oct 2008
    Posts
    9
    Rep Power
    0

    Default

    Do i still start it off with ...

    public static void main(String[] args)

  14. #14
    gnarly hogie is offline Member
    Join Date
    Oct 2008
    Posts
    34
    Rep Power
    0

    Default

    Yes usually you do

  15. #15
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    never mind. deleted. again, good luck.
    Last edited by Fubarable; 10-10-2008 at 04:06 AM.

  16. #16
    str4kt is offline Member
    Join Date
    Oct 2008
    Posts
    9
    Rep Power
    0

    Default

    Alright thx alot gnarly...

    Ill try it myself, and ill post the code and see how it goes.. Thank you once again.

  17. #17
    str4kt is offline Member
    Join Date
    Oct 2008
    Posts
    9
    Rep Power
    0

    Default

    import java.util.Scanner;


    public class Jack {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub


    String str = "Jack";
    str = str.replace('k', '$');
    System.out.println(str);



    It prints out Jac$

    But how do i make it say : Please enter your name:


    I tried adding System.out.println ("Please enter your first name: );

  18. #18
    gnarly hogie is offline Member
    Join Date
    Oct 2008
    Posts
    34
    Rep Power
    0

    Default

    Just a quick question do you take notes in that class?

  19. #19
    str4kt is offline Member
    Join Date
    Oct 2008
    Posts
    9
    Rep Power
    0

    Default

    Lol nope.. He just uses powerpoint slides (Which i have on my laptop) which are direct notes from my notes...

    So no need to.. But I have read the chapters required..

    I still need help though =/

  20. #20
    gnarly hogie is offline Member
    Join Date
    Oct 2008
    Posts
    34
    Rep Power
    0

    Default

    Well here is one tip, save all of your code no matter if its no longer going to be used in that class or not because it will be so much easier to look over as a reference then just some old book. Now you imported the scanner so what you need to do is initialize it by putting in this line of code before you use it

    Scanner variable = new Scanner(System.in);

    after that you need to make some string variables and then use this line of code to take an input

    Stringvariable = scannervariable.next();

    eg. Scanner input = new Scanner(System.in);
    String sname;
    sname = input.next();

Page 1 of 2 12 LastLast

Posting Permissions

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