Change Case

/* Without using toLowerCase() or toUpperCase() */
import java.io.*;
import java.util.Scanner;

class ch_case {
	void upper_case(String text) {

		/* Convert string to character array */
		char textarr[] = text.toCharArray();
		for(int i = 0; i < textarr.length; i++) {
			if(textarr[i] >= 'a' && textarr[i] <= 'z')
				textarr[i] = (char) (textarr[i] - 32);
		}
		String temp = new String(textarr);
		System.out.println("In Uppercase:\n"+temp);
	}
										
	void lower_case(String text) {

		/* Convert string to character array */
		char textarr[] = text.toCharArray();
		for(int i = 0; i < textarr.length; i++) {
			if(textarr[i] >= 'A' && textarr[i] <= 'Z')
				textarr[i] = (char) (textarr[i] + 32);
		}
		String temp = new String(textarr);
		System.out.println("In Lowercase:\n"+temp);
	}
}

class changecase {
	public static void main(String args[ ]) {
		Scanner input = new Scanner(System.in);
		ch_case chc = new ch_case();
		System.out.println("Enter your String:");
		String text = input.nextLine();
		chc.upper_case(text);
		chc.lower_case(text);
	}
}



/* Output */
Enter your String:
Hello World

In Uppercase:
HELLO WORLD

In Lowercase:
hello world

Comments (0)

  • To add your comment please or

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.

Got It!