如何在处理中反转字符串?

How to reverse a string in processing?

我一直在网上搜索很多解决方案,但这是我的问题。 基本上我需要反转一个 4 个字符的字符串:ABCD 变成 DCBA。

程序开始:

import javax.swing.JOptionPane;

String input;

input = JOptionPane.showInputDialog("Enter a string with 4 characters (e.g. ABCD): " );

谢谢

与您在 Java 中的做法相同。

String output = new StringBuilder(input).reverse().toString();

您也可以使用 for 循环遍历字符并自己构建 String