Home » Java programs » Java basic programs

Convert string lowercase to uppercase and vice versa without using library function in java



Here, we are going to learn How to convert string from uppercase or lowercase and vice versa in java without using library function?
Submitted by Preeti Jain, on February 08, 2018

Example 1:

Converting from uppercase to lowercase without using library function.

import java.util.Scanner;

class Lowecase{

	static char ch[] ={'P','R','E','E','T','I'};
	public static void main(String[] args){
		to_Lower(ch);
	}

	//method to convert in lowercase
	public static void to_Lower(char str[]){
		int i=0;
		while(str[i]!='\0'){
			if(str[i]>= 65 && str[i]<=96){
				str[i]+=32;
				System.out.println(str[i]);
			}
			++i;
		}
	}
}

Output

D:\Java Articles>java Lowecase
p
r
e
e
t
i

Example 2:

Converting from lowercase to uppercase without using library function.

import java.util.Scanner;

class Uppcase{

	static char ch[] ={'p','r','e','e','t','t'};
	public static void main(String[] args){
		to_Upper(ch);
	}

	//method to convert in uppercase
	public static void to_Upper(char str[]){
		int i=0;
		while(str[i]!='\0'){
			if(str[i]>= 97 && str[i]<=123){
				str[i]-=32;
				System.out.println(str[i]);
			}
			++i;
		}
	}
}

Output

D:\Java Articles>java Uppcase
P
R
E
E
T
T





Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.



Comments and Discussions


We are using Google to publish ads on our website; Google has its own privacy policies. They may save log, cookies on your system. Google may also collect information of your system like IP address, region, city, country. For more details please go through the Google’s privacy policy.