string rotation
Question:
WAP to find all rotations of a given string. e.g. Java --→ Java, avaJ,vaJa,aJav
💡 Solutions (1)
Super Admin
AdminFeb 09, 2026 at 07:32
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(); } }
Want to add your solution? Login to contribute!
💬 Comments (0)
Login to post comments
No comments yet
Be the first to comment!