Issue
My program will take a string from user via a text field when he presses the button the string should be formatted as shown in the example
An Example will help you understand better
If String Entered is "hello"
Output should be
hello
elloh
llohe
lohel
ohell
hello
The first character must shift to last until the initial word is formed again.
This must work for any length of string
Displaystr =newStr.charAt(newStr.length() - 1) + newStr.substring(0, newStr.length - 1);
I tried this code but It didn't help
Edited - Please don't put question on hold now.
Solution
try this:
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
String text = sc.nextLine();
System.out.println(text);
for(int j=0;j<text.length();j++) {
char firstLetter = text.charAt(0); //get the first letter
text = text.substring(1); //remove the first letter from the input string
text = text + firstLetter;
System.out.println(text);
}
}
}
Answered By - Alexander Mladzhov