string rotation

Java Easy
✅ Solved
Asked by Neelkumar Gohil Feb 03, 2026 at 05:07 Subject: Java Programming

Question:

WAP to find all rotations of a given string. e.g. Java --→ Java, avaJ,vaJa,aJav

💬 0 Comments 💡 1 Solution(s)

💡 Solutions (1)

✅ ACCEPTED SOLUTION

Super Admin

Admin

Feb 09, 2026 at 07:32

👍 0

upvotes

import java.util.Scanner; class StringRotation { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter a string: "); String str = sc.nextLine(); int len = str.length(); System.out.println("All rotations of the string are:"); for (int i = 0; i < len; i++) { String rotation = str.substring(i) + str.substring(0, i); System.out.println(rotation); } sc.close(); } }

👍 Login to Vote

Want to add your solution? Login to contribute!

💬 Comments (0)

Login to post comments

No comments yet

Be the first to comment!