The Mother Board

Motherboards.org forums. Free tech support, motherboard ID, and more.
It is currently Fri Aug 17, 2018 8:54 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 11 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: reverse string in java
PostPosted: Wed Nov 10, 2004 9:11 am 
Offline
Black Belt
Black Belt

Joined: Mon Apr 12, 2004 2:32 pm
Posts: 851
Location: Chicago
for my java class i need to write a method that would take a string the user inputs and output the characters in reverse order. Any ideas on how to do this cause i have no clue. Thanks


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Nov 10, 2004 11:44 am 
Offline
Black Belt 2nd Degree
Black Belt 2nd Degree

Joined: Mon Aug 09, 2004 7:33 pm
Posts: 2740
Location: Milwaukee - Wisconsin
since it's an assignment, can't give you the whole thing. :( assignments, especially in programming, are there for you to learn to think through things yourself. 8)

here's some hints though: :D
.length() is your friend.
each character will need to be appended to the previous in order to output the final string correctly.(append is another reserved word)

just think about how you would need to break it down to do this by hand. and then move your process into "computer terms". one step at a time.

-Roach


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Nov 10, 2004 2:33 pm 
Offline
Black Belt
Black Belt

Joined: Mon Apr 12, 2004 2:32 pm
Posts: 851
Location: Chicago
yea i was thinking of something with the .length() method like
Code:
int i = 0;
while (i < s.length())
{
    s = s.charAt(i);  //like the character of the string at i
    i++;
}
 
return s;


i dont know how to store the difference characters i was thinking in an array but i dont know too much about them and also would i have to say like store length()-1 then length() -2 and so on until the whole string is done.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Nov 10, 2004 4:23 pm 
Offline
Black Belt 2nd Degree
Black Belt 2nd Degree

Joined: Mon Aug 09, 2004 7:33 pm
Posts: 2740
Location: Milwaukee - Wisconsin
try working through some psuedocode first. that also may help.

also, i would recommend trying to work it backwards...perhaps in a for loop or a do-while loop.

char x = selected character
string y = final reversed string

take length - 1 and set it to equal char x(since position 0 is first char)
append this char to a temporary string that comprises the final reversed string.
then just go through the loop until the position is < 0, which would be the end of the string.
then just output string y. :D

of course, the actual coding is missing here, but the idea will work...i've done it. :wink: not the most efficient (so you full-timers back off!) but it'll do what it needs.

-Roach


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Nov 10, 2004 4:44 pm 
Offline
Black Belt
Black Belt

Joined: Mon Apr 12, 2004 2:32 pm
Posts: 851
Location: Chicago
Thanks for the help. I figured it out but now i need to make a method that takes a string and returns the string with no vowels. Any Ideas?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Nov 10, 2004 10:28 pm 
Offline
Black Belt 2nd Degree
Black Belt 2nd Degree

Joined: Mon Aug 09, 2004 7:33 pm
Posts: 2740
Location: Milwaukee - Wisconsin
array of characters(vowels).

compare each char to each of the spots in the array.
if it matches, don't put it in the returned string.

to be totally honest....you should be thinking these through by yourself.
these are the parts of programming which are the most important...because it's the basework. if you don't get these "easy" steps in figuring out small problems, the big ones just become overwhelming pretty quickly. :(

just my $.02

-Roach


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Nov 11, 2004 1:41 pm 
Offline
Black Belt
Black Belt

Joined: Mon Apr 12, 2004 2:32 pm
Posts: 851
Location: Chicago
i figured out the program and everything works to remove the vowels i just used an if statement that compared each char in the string to every different vowel and if they were not equal then it added that char to the final string.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Nov 11, 2004 3:41 pm 
Offline
Black Belt 2nd Degree
Black Belt 2nd Degree

Joined: Mon Aug 09, 2004 7:33 pm
Posts: 2740
Location: Milwaukee - Wisconsin
:D i used to be an "if-else" ladder programmer....but i've kind of been weaned from my profs into one that uses arrays to compare multiple values quickly and efficiently. i haven't had a program yet that really "needed" super-efficient comparisons....but, better to be a little prepared. :wink:

gj w/ getting the prog to work how you wanted it.

-Roach


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Nov 15, 2004 8:31 pm 
Offline
Black Belt 1st Degree
Black Belt 1st Degree

Joined: Wed Sep 22, 2004 9:09 pm
Posts: 1032
Location: Mount Holly New Jersey
I want to go to school for programming:( I cant wait to start writing code again.

_________________
A.C. Ryan | Thrust & HEXX


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Nov 15, 2004 8:36 pm 
Offline
Black Belt 1st Degree
Black Belt 1st Degree

Joined: Wed Sep 22, 2004 9:09 pm
Posts: 1032
Location: Mount Holly New Jersey
I want to go to school for programming:( I cant wait to start writing code again.

_________________
A.C. Ryan | Thrust & HEXX


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ]  Go to page 1, 2  Next

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group