Header Ad

HackerEarth Toggle String problem solution

In this HackerEarth Toggle String problem solution 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.

hackerEarth Toggle String problem solution


HackerEarth Toggle String problem solution.

import java.io.*;
import java.util.*;
class example_2
{
static Scanner sc;
static PrintWriter out;

static void init() throws Exception
{
sc=new Scanner(new File("si.txt"));
out=new PrintWriter(new File("so.txt"));
}

public static void main(String args[]) throws Exception
{
init();
char[] a=sc.next().toCharArray();
for(int i=0;i<a.length;i++)
{
if(a[i]>=97 && a[i]<=122)
{
a[i]-=32;
}
else
{
a[i]+=32;
}
}
for(char ch:a)
{
out.print(ch);
}
out.close();
}
}


Post a Comment

0 Comments