ADVERTISEMENT
ADVERTISEMENT

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
ADVERTISEMENT




ADVERTISEMENT



Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.