diff --git a/Break_a_palindrome.java b/Break_a_palindrome.java new file mode 100644 index 0000000..4d80af3 --- /dev/null +++ b/Break_a_palindrome.java @@ -0,0 +1,34 @@ +/* + +Given a palindromic string of lowercase English letters palindrome, +replace exactly one character with any lowercase English letter so that the resulting string is not a palindrome +and that it is the lexicographically smallest one possible. + +Return the resulting string. If there is no way to replace a character to make it not a palindrome, return an empty string.*/ + +import java.util.*; +import java.io.*; +public class Main +{ + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("Enter the palindrome: "); + String palindrome = sc.nextLine(); + char[] ch = palindrome.toCharArray(); + if(ch.length==1){ + System.out.println(""); + System.exit(0); + } + int i=0; + while(i