Computer Science
Write a program in Java to enter a string in a mixed case. Arrange all the letters of string such that all the lower case characters are followed by the upper case characters.
Sample Input:
Computer Science
Sample Output:
omputercienceCS
Answer
import java.util.Scanner;
public class KboatStringLowerThenUpper
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter string: ");
String str = in.nextLine();
int len = str.length();
StringBuffer sbLowerCase = new StringBuffer();
StringBuffer sbUpperCase = new StringBuffer();
for (int i = 0; i < len; i++) {
char ch = str.charAt(i);
if (Character.isLowerCase(ch))
sbLowerCase.append(ch);
else if (Character.isUpperCase(ch))
sbUpperCase.append(ch);
}
System.out.println("Input String:");
System.out.println(str);
String newStr = sbLowerCase.append(sbUpperCase).toString();
System.out.println("Changed String:");
System.out.print(newStr);
}
}
Output
Related Questions
A string is given as:
Purity of Mind is EssentialWrite a program in Java to enter the string. Count and display:
- The character with lowest ASCII code in lower case
- The character with highest ASCII code in lower case
- The character with lowest ASCII code in upper case
- The character with highest ASCII code in upper case
Sample Output:
The character with lowest ASCII code in lower case: a
The character with highest ASCII code in lower case: y
The character with lowest ASCII code in upper case: E
The character with highest ASCII code in upper case: PWrite a program in Java to accept a string. Arrange all the letters of the string in an alphabetical order. Now, insert the missing letters in the sorted string to complete all the letters between first and last characters of the string.
Sample Input:
computerAlphabetical order:
cemoprtuSample Output:
cdefghijklmnopqrstuWrite a program in Java to accept a string and display the new string after reversing the characters of each word.
Sample Input:
Understanding Computer ScienceSample output:
gnidnatsrednU retupmoC ecneicSWrite a program in Java to accept a string. Count and display the frequency of each character present in the string. The character with multiple frequencies should be displayed only once.
Sample Input:
golden jubileeSample Output:
Alphabet g o l d e n j u b i Frequency 1 1 2 1 3 1 1 1 1 1