Friday, 8 September 2017

Switching Case of String


All the uppercase letters should be converted to lowercase and all the lowercase letters should be converted to uppercase

 
      StringCaseSwith.java  
import java.util.Scanner; /** * all the uppercase letters should be converted to lowercase and all the * lowercase letters should be converted to uppercase */ public class StringCaseSwith { public static void main(String[] args) { String c = ""; String rslt = ""; Scanner scanner = new Scanner(System.in); String str = scanner.next(); for (int i = 0; i < str.length(); i++) { c += str.charAt(i); if (c.equals(c.toUpperCase())) { rslt += c.toLowerCase(); } if (c.equals(c.toLowerCase())) { rslt += c.toUpperCase(); } c = ""; } System.out.println(rslt); } } /* ****** INPUT ******** Rob ******* INPUT ******** ****** OUTPUT ******** rOB ******* OUTPUT ******** */

No comments:

Post a Comment

Search This Blog

Contact us

Name

Email *

Message *