473,387 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

a problem with the reverse method

I have a problem with using the reverse method
any one give me an exmample or correct my error inside this code

Expand|Select|Wrap|Line Numbers
  1. String p="";
  2. for(int x=0 ; x<=3 ; x++)
  3.    p+=x;
  4. System.out.print(p);
  5. String r=reverse(p);
  6. System.out.print(r);
but there is an error at the fifth line
I want to know how to uese the reverse method and print the reversed string

thank u
Jan 31 '07 #1
3 1605
r035198x
13,262 8TB
I have a problem with using the reverse method
any one give me an exmample or correct my error inside this code

Expand|Select|Wrap|Line Numbers
  1. String p="";
  2. for(int x=0 ; x<=3 ; x++)
  3. p+=x;
  4. System.out.print(p);
  5. String r=reverse(p);
  6. System.out.print(r);
but there is an error at the fifth line
I want to know how to uese the reverse method and print the reversed string

thank u
What is the error? Have you written the reverse method? There is no reverse method in the String class. You have to write your own.
Feb 1 '07 #2
dmjpro
2,476 2GB
make sure that what version of j2se u using
the reverse method supported by j2se 1.5
ur user defined code will be like this ....

String reverse(String str)
{
String reverse_str;
char [] char_array = str.toCharArray();
char [] char_array1 = new char[str.length()];
int j = 0;
for(int i=str.length()-1;i>=0;i++)
char_array1[j++] = char_array[i];
return reverse_str = new String(char_array1);
}

try this code ...then reply me....
if don't want to use my user defined code then u can use StringBuffer class
for details plz link to ..........http://java.sun.com/j2se/1.4.2/docs/api/java/lang/StringBuffer.html
thanksssssssssss.............
Feb 2 '07 #3
horace1
1,510 Expert 1GB
I have a problem with using the reverse method
any one give me an exmample or correct my error inside this code

Expand|Select|Wrap|Line Numbers
  1. String p="";
  2. for(int x=0 ; x<=3 ; x++)
  3.    p+=x;
  4. System.out.print(p);
  5. String r=reverse(p);
  6. System.out.print(r);
but there is an error at the fifth line
I want to know how to uese the reverse method and print the reversed string

thank u
try StringBuilder
Expand|Select|Wrap|Line Numbers
  1.   String p="hello sam";
  2.   System.out.println(p);
  3.   StringBuilder s=new StringBuilder(p);
  4.   String r=s.reverse().toString();
  5.   System.out.println(r);
Feb 2 '07 #4

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

Similar topics

35
by: Raymond Hettinger | last post by:
Here is a discussion draft of a potential PEP. The ideas grew out of the discussion on pep-284. Comments are invited. Dart throwing is optional. Raymond Hettinger ...
59
by: Raymond Hettinger | last post by:
Please comment on the new PEP for reverse iteration methods. Basically, the idea looks like this: for i in xrange(10).iter_backwards(): # 9,8,7,6,5,4,3,2,1,0 <do something with i> The...
3
by: engsolnom | last post by:
I need to use the built-in method 'reverse', but notice strange behavior. Foe example: print my_list.reverse() doesn't work. new_list = my_list.reverse() doesn't work. my_list.reverse()...
40
by: Xah Lee | last post by:
is it possible in Python to create a function that maintains a variable value? something like this: globe=0; def myFun(): globe=globe+1 return globe
2
by: nafri | last post by:
i have a colleciton that i need to reverse. Array has a reverse method. Is their any direct way to transfer the items in the collection to an array or arraylist, reverse the array and transfer back...
8
by: Gregory Piñero | last post by:
Is my mind playing tricks on me? I really remember being able to reverse a string as in: text='greg' print text.reverse() Is it possible thats in some Python install and not in others? I...
41
by: rick | last post by:
Why can't Python have a reverse() function/method like Ruby? Python: x = 'a_string' # Reverse the string print x Ruby: x = 'a_string' # Reverse the string
3
by: analoveu | last post by:
I want to know if there is a built-in method in the java class library and ready for use .If there how can i use it to reverse a string and print it I saw i the JDK6.0 Docs this method java.lang...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.