Remove all lowercase characters in the string

Problem statement:-  Program to Remove all lowercase characters in the string

 Data requirement:-

   Input Data:- str

  Output Data:- str or Final_String (In Python)

  Additional Data:-i, j len in C++/Java or ch and str2 in Python

Program in C

Here is the source code of the C Program to Remove all lowercase characters in the string.

Code:

#include<stdio.h>
int main()
{
    char str[30];
    printf("Enter your String:");
    scanf("%[^\n]",str);
    int i,j;

     for (i = 0; str[i] != '\0'; ++i) {
     while (str[i] >= 'a' && str[i] <= 'z') {
         for (j = i; str[j] != '\0'; ++j) {
            str[j] = str[j + 1];
         }
         str[j] = '\0';
      }
   }
       printf("After removing lowercase letter string is: %s\n",str);
}

Input/Output:
Enter your String:CsInfo DoT
After removing lowercase letter string is: CI DT

Program in C++

Here is the source code of the C++ Program to Remove all lowercase characters in the string.

Code:

#include<iostream>
using namespace std;
int main()
{
    string str;
    cout<<"Enter your String:";
    getline(cin,str);
    int len=0;
    while(str[len]!='\0')
    {
        len++;
    }
    int i,j;

     for (i = 0; str[i] != '\0'; ++i) {
     while (str[i] >= 'a' && str[i] <= 'z') {
         for (j = i; str[j] != '\0'; ++j) {
            str[j] = str[j + 1];
         }
         str[j] = '\0';
      }
   }
       cout<<"After removing lowercase letter string is: "<<str;
}

Input/Output:
Enter your String:ProGram
After removing lowercase letter string is: PG

Program in Java

Here is the source code of the Java Program to Remove all lowercase characters in the string.

Code:

import java.util.Scanner;
public class p33 {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
String str1;
System.out.println("Enter your String:");
str1=cs.nextLine();
str1+='\0';
char[] str=str1.toCharArray();
int i,j;
for (i = 0; str[i] != '\0'; ++i) {
     while (str[i] >= 'a' && str[i] <= 'z') {
         for (j = i; str[j] != '\0'; ++j) {
            str[j] = str[j + 1];
         }
         str[j] = '\0';
      }
   }
System.out.println("After removing lowercase letter string is: ");
for (i = 0; str[i] != '\0';i++)
System.out.print(str[i]);
    cs.close();
}
}

Input/Output:
Enter your String:
JavA StrInG PrOgRam
After removing lowercase letter string is: 
JA SIG POR

Program in Python

Here is the source code of the Python Program to Remove all lowercase characters in the string.

Code:

str=input("Enter the String:")
str2 = []
i = 0
while i < len(str):
    ch = str[i]
    if not ch.islower():
        str2.append(ch)
    i += 1
Final_String = ''.join(str2)
print("After removing lowercase letter string is:",Final_String)

Input/Output:
Enter the String:CsInFo
After removing lowercase letter string is: CIF


More:-

C/C++/Java/Python Practice Question 


Post a Comment

0 Comments