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
i don't know java, but the baisc process woulmd be this
-make an array the size of the length of your string
-make a for loop iterating up(++) to the strings length (lets call it i)
-take originalString[i] and place it in newString[originalString-i]
that should do it
__________________
photoshop too expensive? use the GIMP! www.gimp.org
You could do it without the array, i'd write it like this in javascript, would be damn similar in java:
Code:
var result;
result = '';
for (var position = 0; position < aString.length; position = position + 1)
{
result = aString.charAt(position) + result
};
return result
You could do it without the array, i'd write it like this in javascript, would be damn similar in java:
Code:
var result;
result = '';
for (var position = 0; position < aString.length; position = position + 1)
{
result = aString.charAt(position) + result
};
return result
You realize you just did his homework for him right?
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Thanks a lot for the help ive been working on this all week and i couldnt figure it out. So now my next problem is i have to make a method that takes a string and removes the vowels then returns the string. Any Ideas?
Couple ways to do this, but I would recommend using the stringbuffer. These objects are made for modifying strings. Just create an array of vowel characters and make your comparisons. Loop through the stringbuffer and check to see if the character matches any index in the vowel array, if yes, delete it, if no, move on. Later.
Loop through the string changing each character to an int. Then check using the dec. value it returns. It's easier if you convert it to all lower case. If the character does not fall into one of the ranges you set, add it to a new string.
That's probably more of the way they want it done. If you want it done quick and easy look through here.
Last edited by squirellplaying; 11-11-2004 at 11:43 AM..
Thanks a lot for the help ive been working on this all week and i couldnt figure it out. So now my next problem is i have to make a method that takes a string and removes the vowels then returns the string. Any Ideas?
lol, i had to do the exact same thing back in my old course. What/where are you doing this for study?
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.