Update OOP/Java/Lab/Week9/palin_alpha_rev_concat.java

This commit is contained in:
Aadit Agrawal 2024-10-14 09:56:35 +05:30
parent 0bdd6abbbc
commit e0f55e7fd5

View File

@ -1,29 +1,26 @@
import java.util.Scanner;
import java.util.Arrays;
class palin_alpha_rev_concat{
static boolean palindrome(String str)
{
String rev=reverse(str);
return str.contentEquals(rev);
}
static String[] alphabetic(String str)
{
String arr[]=str.split(" ");
for(int i=0;i<arr.length-1;i++)
{
for(int j=0;j<arr.length-i-1;j++)
{
int a=arr[j].compareTo(arr[j+1]);
if(a>0)
{
String temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
return arr;
static String[] alphabetic(String str) {
char[] arr = str.toCharArray();
Arrays.sort(arr);
String sortedStr = new String(arr);
String[] result = new String[sortedStr.length()];
for (int i = 0; i < sortedStr.length(); i++) {
result[i] = String.valueOf(sortedStr.charAt(i));
}
return result;
}
static String reverse(String str)
{
StringBuffer rev=new StringBuffer(str);
@ -52,13 +49,11 @@ class palin_alpha_rev_concat{
System.out.println("String is a palindrome:"+palindrome(str));
break;
}
case 2:
{
case 2: {
String arr[] = alphabetic(str);
System.out.println("String in alphabetic order:");
for(int i=0;i<arr.length;i++)
{
System.out.print(arr[i]+" ");
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i]);
}
System.out.println();
break;