In this context, we will learn how to move all the capital letters to the end of a string in Java.
Separate small and capital letters from a string in Java
So if the user enters Let us Learn Java Output will be et us earn avaLLJ.
import java.util.*; public class captialToEnd { void fetchTheString(String inputstring) { int j; int lengthOfstring = inputstring.length(); String alplower = ""; String alpupper = ""; char temp; for (j = 0; j < lengthOfstring; j++) { temp = inputstring.charAt(j); if (temp >= 'A' && temp <= 'Z') { alpupper+= temp; } else { alplower += temp; } } System.out.println(alplower + alpupper); } public static void main(String args[]) { String inputstring; Scanner in=new Scanner(System.in); System.out.println("Enter the String:"); inputstring=in.next(); captialToEnd ce=new captialToEnd(); ce.fetchTheString(inputstring); } }
output: