Write a Java Program to Convert Uppercase to Lowercase with an example. In this section, we use built-in functions, loops, and ASCII values to get the result. In this Java Uppercase to Lowercase example, we use the built-in function toLowerCase() on the given string.
import java.util.Scanner;
public class UpperToLower1 {
private static Scanner sc;
public static void main(String[] args) {
String uppStr;
sc= new Scanner(System.in);
System.out.print("\nEnter Uppercase String to convert = ");
uppStr = sc.nextLine();
String uppStr2 = uppStr.toLowerCase();
System.out.println("\nThe Lowercase String = " + uppStr2);
}
}

Here, in this Convert Uppercase to Lowercase example, first, we converted the uppStr string to upch character array using the toCharArray().
Next, we used a For loop to iterate the upch character array from start to end. Within the loop, we check whether the character at the index position is greater than or equal to A & less than or equal to Z. If it is True, we add 32 to the existing ASCII value. For example, A = 65, when we add 32, it becomes 97, and the ASCII value of a = 97.
import java.util.Scanner;
public class UpperToLower2 {
private static Scanner sc;
public static void main(String[] args) {
String uppStr;
int i;
sc= new Scanner(System.in);
System.out.print("\nPlease Enter Uppercase String = ");
uppStr = sc.nextLine();
char[] upch = uppStr.toCharArray();
for(i = 0; i < upch.length; i++)
{
if(upch[i] >= 'A' && upch[i] <= 'Z') {
upch[i] = (char) ((int)upch[i] + 32);;
}
}
System.out.print("\nThe Lowercase String = ");
for(i = 0; i < upch.length; i++) {
System.out.print(upch[i]);
}
}
}
Please Enter Uppercase String = LEARN JAVA
The Lowercase String = learn java
Java Program to Convert Uppercase to Lowercase Example 3
Here, we haven’t changed the uppStr string to a char array. Next, we used the charAt function in Java on the uppStr to get the character at the index position. Then, we assigned each character to lowStr2.
import java.util.Scanner;
public class UpperToLower3 {
private static Scanner sc;
public static void main(String[] args) {
String uppStr, lowStr2 = "";
int i;
sc= new Scanner(System.in);
System.out.print("\nEnter Uppercase String to convert = ");
uppStr = sc.nextLine();
char ch;
for(i = 0; i < uppStr.length(); i++)
{
if(uppStr.charAt(i) >= 'A' && uppStr.charAt(i) <= 'Z') {
ch = (char) (uppStr.charAt(i) + 32);
}
else {
ch = (char) (uppStr.charAt(i));
}
lowStr2 += ch;
}
System.out.print("\nThe Lowercase String = " + lowStr2);
}
}
Enter Uppercase String to convert = HAPPY PROGRAMMING
The Lowercase String = happy programming
In this Uppercase to Lowercase example, instead of assigning it to a new string, we print each character within the loop.
import java.util.Scanner;
public class UpperToLower4 {
private static Scanner sc;
public static void main(String[] args) {
String uppStr;
int i;
sc= new Scanner(System.in);
System.out.print("\nEnter Uppercase String to convert = ");
uppStr = sc.nextLine();
System.out.print("\nThe Lowercase String = ");
for(i = 0; i < uppStr.length(); i++)
{
char ch = uppStr.charAt(i);
if(ch >= 'A' && ch <= 'Z') {
ch = (char) (ch + 32);
}
System.out.print(ch); // Str2 += ch;
}
}
}
Enter Uppercase String to convert = HELLO WORLD
The Lowercase String = hello world
In this Program to Convert Uppercase to Lowercase using ASCII Values, we compare the ASCII values instead of comparing characters.
import java.util.Scanner;
public class UpperToLower5 {
private static Scanner sc;
public static void main(String[] args) {
String uppStr1, lowStr2 = "";
int i;
sc= new Scanner(System.in);
System.out.print("\nEnter Uppercase String to convert = ");
uppStr1 = sc.nextLine();
for(i = 0; i < uppStr1.length(); i++)
{
char ch = uppStr1.charAt(i);
if(ch >= 65 && ch <= 90) {
ch = (char) (ch + 32);
}
lowStr2 += ch;
}
System.out.print("\nThe Lowercase String = " + lowStr2);
}
}
Enter Uppercase String to convert = JAVA PROGRAMMING
The Lowercase String = java programming
In this code for Uppercase to Lowercase, we separated the logic using functions.
import java.util.Scanner;
public class UpperToLower6 {
private static Scanner sc;
public static void main(String[] args) {
String uppStr, lowStr2;
sc= new Scanner(System.in);
System.out.print("\nEnter Uppercase String to convert = ");
uppStr = sc.nextLine();
lowStr2 = toUpper(uppStr);
System.out.print("\nThe Lowercase String = " + lowStr2);
}
public static String toUpper(String uppStr) {
String lowStr2 = "";
for(int i = 0; i < uppStr.length(); i++)
{
char ch = uppStr.charAt(i);
if(ch >= 65 && ch <= 90) {
ch = (char) (ch + 32);
}
lowStr2 += ch;
}
return lowStr2;
}
}
Enter Uppercase String to convert = 30 SEP JAVA CODING!
The Lowercase String = 30 sep java coding!