ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2008 ICSE Computer Science Paper



Share with a Friend

Solved 2008 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Reverse Uppercase & Lowercase in String Program - ICSE 2008 Computer Science

Write a program to input a string and print out the text with the uppercase and lowercase letters reversed, but all other characters should remain the same as before.
Example:
INPUT: WelComE TO School
OUTPUT: wELcOMe to sCHOOL

import java.util.Scanner; class Reverse{ public static void main(String args[]){ Scanner in = new Scanner(System.in); System.out.print("Enter the string: "); String s = in.nextLine(); String t = ""; for(int i = 0; i < s.length(); i++){ char ch = s.charAt(i); if(Character.isUpperCase(ch)) t += Character.toLowerCase(ch); else t += Character.toUpperCase(ch); } System.out.println(t); } }

Output

 
 OUTPUT  : 
Enter the string: WelComE TO School
wELcOMe to sCHOOL