Rotate String - N Positions JAVA - EASY - PART005
Rotate String - N Positions
A string S of length L is passed as the input. The program must rotate the string S by N position in forward direction and print the result as the output.
***********************************************************************************
import java.util.*;
public class Hello {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
int a=sc.nextInt();
int l=s.length();
System.out.print(s.substring(l-a,l)+s.substring(0,l-a));
}
}
***********************************************************************************
Comments
Post a Comment