Results 1 to 20 of 24
Thread: Need help~~~ Midterm tomorrow!!!
- 10-10-2008, 03:46 AM #1
Member
- Join Date
- Oct 2008
- Posts
- 9
- Rep Power
- 0
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.
- 10-10-2008, 03:48 AM #2
Member
- Join Date
- Oct 2008
- Posts
- 34
- Rep Power
- 0
Go search through the String API's on Suns website you will find it.
- 10-10-2008, 03:48 AM #3
Member
- Join Date
- Oct 2008
- Posts
- 9
- Rep Power
- 0
Huh? Whats the mean >_>...
I don't even know how to start off with this problem..
-
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.
-
- 10-10-2008, 03:50 AM #6
Member
- Join Date
- Oct 2008
- Posts
- 9
- Rep Power
- 0
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?
- 10-10-2008, 03:51 AM #7
Member
- Join Date
- Oct 2008
- Posts
- 34
- Rep Power
- 0
- 10-10-2008, 03:51 AM #8
Member
- Join Date
- Oct 2008
- Posts
- 9
- Rep Power
- 0
Nope he hasn't.
- 10-10-2008, 03:54 AM #9
Member
- Join Date
- Oct 2008
- Posts
- 34
- Rep Power
- 0
Is your trouble with finding the method to do that or implementing a method?
- 10-10-2008, 03:55 AM #10
Member
- Join Date
- Oct 2008
- Posts
- 9
- Rep Power
- 0
Well it says insert a method named "replace"... How would I do that?
- 10-10-2008, 03:57 AM #11
Member
- Join Date
- Oct 2008
- Posts
- 34
- Rep Power
- 0
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');
- 10-10-2008, 03:59 AM #12
Member
- Join Date
- Oct 2008
- Posts
- 34
- Rep Power
- 0
Oh and most methods if not all are something like that you just need to know the parameters
- 10-10-2008, 03:59 AM #13
Member
- Join Date
- Oct 2008
- Posts
- 9
- Rep Power
- 0
Do i still start it off with ...
public static void main(String[] args)
- 10-10-2008, 04:02 AM #14
Member
- Join Date
- Oct 2008
- Posts
- 34
- Rep Power
- 0
Yes usually you do
-
never mind. deleted. again, good luck.
Last edited by Fubarable; 10-10-2008 at 04:06 AM.
- 10-10-2008, 04:07 AM #16
Member
- Join Date
- Oct 2008
- Posts
- 9
- Rep Power
- 0
Alright thx alot gnarly...
Ill try it myself, and ill post the code and see how it goes.. Thank you once again.
- 10-10-2008, 04:38 AM #17
Member
- Join Date
- Oct 2008
- Posts
- 9
- Rep Power
- 0
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: );
- 10-10-2008, 04:45 AM #18
Member
- Join Date
- Oct 2008
- Posts
- 34
- Rep Power
- 0
Just a quick question do you take notes in that class?
- 10-10-2008, 04:47 AM #19
Member
- Join Date
- Oct 2008
- Posts
- 9
- Rep Power
- 0
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 =/
- 10-10-2008, 04:52 AM #20
Member
- Join Date
- Oct 2008
- Posts
- 34
- Rep Power
- 0
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();


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks