字符逆序

将一个字符串str的内容颠倒过来,并输出。数据范围:

输入描述:

输入一个字符串,可以有空格

输出描述:

输出逆序的字符串

示例1

输入

I am a student

输出

tneduts a ma I

示例2

输入

nowcoder

输出

redocwon

Java 编程

package cn.net.javapub.javaintroduction.example;

/**
 * @author: shiyuwang
 */

import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        char[] chars = new char[100];
        int i = 0;
        for (; i < 100; i++) {
            int read = System.in.read();
            if (read == 10) break;
            chars[i] = (char) read;
        }
        i--;
        for (; i >= 0; i--) {
            System.out.print(chars[i]);
        }
    }
}

展示效果:

华为OD机试 - 字符逆序 (Java 2024 E卷 100分)_开发语言