Java Program ( Shifting every character one position to the right)

Hello people,

Anyone of you know how to use BlueJ to write a program that will shift every character one position to the right?.

Example: if the command argument is the String "Java", the program should display the result:

avaj

vaja

ajav

java

I know how to write the program to produce the result:

*^^^

^*^^

^^*^

^^^*

but i have no idea how to do it in String

Please help me with it

Thank you

[484 byte] By [qunjie1984a] at [2007-11-26 19:32:05]
# 1

> ...

>

> but i have no idea how to do it in String

>

> Please help me with it

>

> Thank you

If you really have no idea at all, then I cannot help you. You'd better ask your teacher or read your course book how to program in Java.

prometheuzza at 2007-7-9 22:02:57 > top of Java-index,Java Essentials,Java Programming...
# 2

> I know how to write the program to produce the

> result:

>

> ...

Ah, you know how to program.

Use a for statement to loop a n-number of times, where n is the length of the String. Print the String in the for-statement and then get the first character of the String and place it at the end of the String:

String s = "java";

for(...) {

print 's'

s = [substring of 's' from index 1 -> end] + [substring of 's' from index 0 -> 1]

}

Have a look at the String API docs:

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html

especially at the substring(...) methods.

prometheuzza at 2007-7-9 22:02:57 > top of Java-index,Java Essentials,Java Programming...