Write a java program to enter a string in mixed case. Arrange all the letters of the string such that all the lower case character s followed by the upper case characters.
Answers
Answer:
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a string:");
String x = sc.next();
ArrayList<Character> lowerCase = new ArrayList<>();
ArrayList<Character> upperCase = new ArrayList<>();
int n = x.length();
for(int i = 0; i < n-1; i++){
if(Character.isLowerCase(x.charAt(i))){
lowerCase.add(x.charAt(i));
}
else{
upperCase.add(x.charAt(i));
}
}
String j = "" , y = "";
for (char c : lowerCase){
j += c;
}
for (char c : upperCase){
y += c;
}
System.out.println("Original string:" + x);
System.out.println("String after putting lower case Characters in the first and upper case Characters in the end:" + (j+y));
}
}
Explanation: