Enter a string, and then tell the string loop to move right 4 bits
such as input abcdefgh
The output EFGHABCD
Here are two methods, the first is to convert the string to a character array char[];
Import java.util.*;
Class move
{public
static void Main (string[] args)
{
Scanner sc=new Scanner (system.in);
String Str=sc.next ();
Char[] Rt=new char[str.length ()];
for (int i=0;i<str.length (); i++)
Rt[i]=str.charat (i);
for (int i=0;i<str.length (); i++)
{
if (i>str.length ()-5)
rt[(i%4)]=str.charat (i);
else Rt[i+4]=str.charat (i);
}
System.out.println (RT);
}
Here is the second method, which uses the StringBuilder replace method to pass in the parameter start,end,replacement
Import java.util.*;
Class move
{public
static void Main (string[] args)
{
Scanner sc=new Scanner (system.in);
String Str=sc.next ();
StringBuilder sb=new StringBuilder (str);
for (int i=0;i<str.length (); i++)
{
if (i>str.length ()-5)
Sb.replace (i%4, (i%4) +1,new String (new Char[]{str.charat (i)}));
else
sb.replace (i+4,i+5,new String (new Char[]{str.charat (i)}));
System.out.println (SB);
}
If you want to use the Replace method of string, it is not feasible to experiment, because the replace method of the string will only replace one part and cannot change the entire string to StringBuilder.