473,480 Members | 1,711 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

reversing characters in a word

16 New Member
Hello,
I am new to java and i was having a hard time figuring out on how to do certain string manipulations. I was asked to read in a text file and reverse the words. So far, I have put all the words in the text file into an arraylist.
For example...
Hello World. ---> must be printed out as --> olleH .dlroW
right now when i print my arraylist i am getting
[ Hello, World.] I was thinking of somehow accessing each word from here and reversing it. But i am stuck at this point. ANy help would
be appreciated.
thanks
Jan 16 '07 #1
4 2690
Soujiro
35 New Member
From there.. You can do it in many ways.. Because you are new Ill teach you a slow, inefficent but easy one.

here is the pseudocode:
Expand|Select|Wrap|Line Numbers
  1.     MainFunction()
  2.     {
  3.         loop while list is not empty
  4.         { 
  5.             String something = getFrom list
  6.             print( reverseFunc(something) );
  7.             nextValueinList();
  8.         } 
  9.     }
  10.  
  11.     String reverseFunc( String something )
  12.     {
  13.         String temporary = something;
  14.         String result="";
  15.         for( int i=temporary.size()-1; i>= 0; i-- )
  16.         {
  17.             result+=temporary.charAt( i );
  18.         }
  19.         return result;
  20.     }
  21.  
The function was not tested though but i guess you can make it run..
Jan 16 '07 #2
hello12
16 New Member
I was trying to work on the code but i keep getting the error
cannot find symbol
symbol : method size()
location: class java.lang.String
for(int i = (temp.size()-1);i>=0;i--)
I did import java.io and java.util in the beginning of the program.
thanks in advance :)
Jan 16 '07 #3
hello12
16 New Member
it worked!!!!! thankyou.
i changed the code a little bit..
for(int i = (temp.length() -1); i>=0;i--)
Jan 16 '07 #4
r035198x
13,262 MVP
it worked!!!!! thankyou.
i changed the code a little bit..
for(int i = (temp.length() -1); i>=0;i--)
Size of arraylist is given by .size()
Length of string is given by .length()
Jan 16 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
6879
by: Markus Ernst | last post by:
Hi I wrote a function that "normalizes" strings for use in URLs in a UTF-8 encoded content administration application. After having removed the accents from latin characters I try to remove all...
1
2080
by: Jay Azurin | last post by:
Hello, I'm trying to create a memory dump parser tool for which I plan to use existing header files that contain structures of registers. My plan is to use a union and include the structures in...
3
17938
by: john | last post by:
I need to produce a RTF-document which is filled with data from a database. I've created a RTF-document in WordPad (a template, so to speak) which contains 'placeholders', for example '<dd01>',...
1
6904
by: j | last post by:
Hi, I've been trying to do line/character counts on documents that are being uploaded. As well as the "counting" I also have to remove certain sections from the file. So, firstly I was working...
25
5285
by: Wim Cossement | last post by:
Hello, I was wondering if there are a few good pages and/or examples on how to process form data correctly for putting it in a MySQL DB. Since I'm not used to using PHP a lot, I already found...
8
4738
by: arnuld | last post by:
i have created a solutions myself. it compiles without any trouble and runs but it prints some strange characters. i am not able to find where is the trouble. ...
3
2023
by: kellysgirl | last post by:
Private Sub displayButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles displayButton.Click ' creates and displays a new password Dim origPassword As String ...
2
12048
by: Kelly B | last post by:
I tried to write a code which would reverse the order of words in a given string. I.e if Input String=The C Programming Language Output String=Language Programming C The Here is the code...
7
5081
by: benn686 | last post by:
Anyone know of an efficient way of reversing the bits of a word??
0
7044
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7045
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
6944
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4782
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2985
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
182
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.