Advertisement
fbinnzhivko

Untitled

Jul 29th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. import static jdk.nashorn.internal.objects.NativeString.toUpperCase;
  4.  
  5. public class _21_Change_to_sentenceToUppercase {
  6.     public static void main(String[] args) {
  7.  
  8.         Scanner scanIn = new Scanner(System.in);
  9.         String text = scanIn.nextLine();
  10.  
  11.         String openTag = "<upcase>";
  12.         String closeTag = "</upcase>";
  13.         String modified = "";
  14.  
  15.         for (int i = 0; i < text.length(); i++) {
  16.  
  17.             int indexOpen = text.indexOf(openTag, i);
  18.             int indexClose = text.indexOf(closeTag, i);
  19.             if (i == indexOpen)
  20.             {
  21.                 if (indexOpen != -1 && indexClose != -1)
  22.                 {
  23.                     for (int j = indexOpen + openTag.length(); j < indexClose; j++)
  24.                     {
  25.                         modified += text.toUpperCase().charAt(j);
  26.                     }
  27.                     i += indexClose - indexOpen + closeTag.length();
  28.                 }
  29.             }
  30.             if (i < text.length())
  31.             {
  32.                 modified += text.charAt(i);
  33.             }
  34.         }
  35.         System.out.print(modified);
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement