BeginnersBook.in

Programming For Geeks

  • Home
  • All Tutorials
    • Learn C
    • Learn Python
  • Programs
    • Java Programs
    • C++ Programs
    • C Programs
  • Algorithms
    • Sorting
  • MCQ’s
    • MySQL
    • Operating System
  • WordPress
    • Genesis Pro Themes
    • Blogs
  • Tools
    • Direct Download Link Generator
    • HTML Compiler
  • How to
    • Web Examples
  • Write For Us

Java program to Invert Case of a String | Toggle String

September 16, 2018 By Mr. Robot

You have been given a String S consisting of uppercase and lowercase English alphabets. You need to change the case of each alphabet in this String. That is, all the uppercase letters should be converted to lowercase and all the lowercase letters should be converted to uppercase. You need to then print the resultant String to output.

Input Format
The first and only line of input contains the String

Output Format
Print the resultant String on a single line.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import java.util.*;
class ToggleString {
public static void main(String[] args){
   Scanner sc= new Scanner(System.in);
   String str = sc.nextLine();
   char arr[]=str.toCharArray();
   for(int i=0; i<arr.length; i++)
   {
       if(Character.isLowerCase(arr[i]))
           System.out.print(Character.toUpperCase(arr[i]));
       else if(Character.isUpperCase(arr[i]))
           System.out.print(Character.toLowerCase(arr[i]));
   }
  }
}
When you run program, the output will be following:
1
2
JAVASimplified
javasIMPLIFIED

Filed Under: Java examples

Related Posts

  • Java Program to Multiply Two Numbers Without using ‘ ∗ ‘ Operator
  • Java Program to Find ASCII Value of a Character
  • Java program to add two integer in range of (4 bytes)

Recent Posts

  • Download Grand Theft Auto: Vice City Audio File | Highly Compressed
  • Grand Theft Auto: Vice City Game Download For PC | Full Setup
  • SQL SHOW DATABASES Statement
  • Direct view storage Tube (DVST) in Computer Graphics
  • CRT Color Monitor in Computer Graphics

Java Examples

  • More 300+ Java Programs
  • Hello, World
  • Add Two Numbers
  • Area of Triangle
  • Arithmetic Operation
  • Palindrome String
  • Upper or LowerCase
  • Leap Year
  • Toggle String
  • Automorphic Number
  • Neon Number
  • Strong Number
  • Spy Number

Pattern Examples

  • Simple (*) Pattern Programs
  • Tricky (*) Pattern Programs
  • Wave Pattern Programs

More…

  • C++ Programs
  • C Programs

Copyright © 2019 - BeginnersBook.in - All Right Reserved || Sitemap