Right Rotate String
This program performs right rotation of a string.
Problem Statement
Write a Java program to right rotate string "Eduinq" by 2 positions.
Source Code
| 1 | public class RightRotateString { |
| 2 | public static void main(String[] args) { |
| 3 | System.out.println("Eduinq Right Rotate String"); |
| 4 | String str="Eduinq"; |
| 5 | int d=2; |
| 6 | String rotated=str.substring(str.length()-d)+str.substring(0,str.length()-d); |
| 7 | System.out.println("Right rotated string: "+rotated); |
| 8 | } |
| 9 | } |
Program Output
Eduinq Right Rotate String Right rotated string: nqEdui
Explanation
Right rotation takes last d characters and moves them to front. - substring() extracts parts accordingly. - Together demonstrates right rotation of string. Conclusion: Shows how to perform right rotation of string.