[Java] Capitalize only the specified range in substring. (How to use substring)

less than 1 minute read

```java /* substring extracts characters. The argument contains the character index. *Index starts from 0 */

/* With two arguments Example: String str = “012345”; substring(start position, end position); substring(0, 3) The extracted characters are [012] *The ending position is 3, but it is not included in the extracted characters.

If there is one argument, it is the start position. Example: String str = “012345”; substring (start position); substring(3); The extracted characters are [345] */

/* *Blank is included in the index String str = “0 12345”; (white space) substring (start position); substring(3); The extracted characters are [2345] */

import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in);

    int a = sc.nextInt();
    int b = sc.nextInt();
    sc.nextLine();
    String str = sc.nextLine();
    
    System.out.println(str.substring(0, a-1) + str.substring(a-1, b).toUpperCase() + str.substring(b));
} } 

Tags:

Updated: