S
S
Sawayadi2020-11-17 17:17:08
Java
Sawayadi, 2020-11-17 17:17:08

How to capitalize values ​​in a row with a paired index?

I have a row and I need to display it in such a way that the characters with the paired index are uppercase.
For example
Row: katya here
Result: kaTya here
I tried to do it through for, but it only finds paired indices and displays them in capitals.
Here is the code itself:

package com.company;
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Ведите строку: ");
        String s = in.nextLine();
        char[] strToArray = s.toCharArray();
        for(int i = 0; i < strToArray.length; i+= 2) {
            System.out.print(strToArray[i] + "\t");
        }
}
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question