Left Rotate String
This program performs left rotation of string.
Problem Statement
Write a Java program to left rotate string "Eduinq" by 2 positions.
Source Code
| 1 | public class LeftRotateString { |
| 2 | public static void main(String[] args) { |
| 3 | System.out.println("Eduinq Left Rotate String"); |
| 4 | String str="Eduinq"; |
| 5 | int d=2; |
| 6 | String rotated=str.substring(d)+str.substring(0,d); |
| 7 | System.out.println("Left rotated string: "+rotated); |
| 8 | } |
| 9 | } |
Program Output
Eduinq Left Rotate String Left rotated string: duinqE
Explanation
The string is split at the rotation index d, and the second part is concatenated before the first part, together achieving a left rotation of the string.