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
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
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