473,412 Members | 5,714 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,412 software developers and data experts.

Having trouble with my code.

3
I am write a program rotate()
This method is supposed to bring the the # of end letters to the front based on the user input

for example:
String word = "hellos";
tester.rotate(word,1); results in shello

tester.rotate(word,5); results in hello [which would be the limit because hello has word length of 5]
The following is the code that I wrote to rotate once and so on.
I am working on making the code general and so specific such as if I say rotation = rotationable and let the user try different int values based on the word length. For some reason, my general code is not really working and I need help

if (rotation == 1)
{
for (int i = word.length()-1; i>=word.length()-1; i--)
{
rotated = rotated + word.charAt(i);
}
for (int i = 0; i<=word.length()-2; i++)
{
rotated = rotated + word.charAt(i);
}
}
System.out.println(tester.rotate(word, 1));

I cannot seem to come up with a code that will let me input any int value instead of 1 with out saying rotation == 1 in my real code.

Answer: shello

If you want to see what I am working on, I will send it.
Apr 3 '07 #1
1 1205
JosAH
11,448 Expert 8TB
Allow me to show you quite a different (and more powerful) approach; suppose
you want to do this AAAAABBB ---> BBBAAAAA, i.e. you want to move the
last n == 3 characters to the front. For notational convenience let aaaaa be the
reverse of the sequence AAAAA. Here are the steps involved:

1) reverse the entire string:

AAAAABBB ---> bbbaaaaa

2) reverse the first three characters:

bbbaaaaa ---> BBBaaaaa

3) reverse the last five characters:

BBBaaaaa ---> BBBAAAAA

All you have to do now is check the substring() method in the String class and
the reverse method in the StringBuffer class.

kind regards,

Jos
Apr 3 '07 #2

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

Similar topics

1
by: Anand | last post by:
Hi i am having trouble adding a recordset into the access database, the code seems to be working fine it passs and parses through all variables just fine without showing any errors and also when i...
9
suzee_q00
by: suzee_q00 | last post by:
I will admit that lots of times the obvious eludes me and this is most likely one of those times but if anyone has any ideas on what I can do to make this code work, I would greatly appreciate it....
3
by: Michael | last post by:
Hi all, I'm having trouble PInvoking a TCHAR within a struct. I'll paste the specific struct's API definition below. I've tried so many numerous variations. The main Win32 error I get is...
2
by: Stu | last post by:
Hi guys, I've been having trouble getting the clock function to work portably, please could I get some thoughts? <Possibly OT comments> It works fine on my laptop (under WinXP) and on my...
24
by: GesterX | last post by:
First of all I'm new to this site but it certainly looks like a place that i will be visiting more often! Onto my problem. I am creating a Hotel Bussiness project in java using BlueJ The...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.