String 反向输出字符串
2013-10-16 23:40
211 查看
package String; /** * 反向输出字符串 */ import java.util.Scanner; public class reversal { public static void main(String[] args) { System.out.println("Please enter the String:"); String str = new Scanner(System.in).nextLine(); // 输入字符串 toReverse1(str); toReverse2(str); } public static void toReverse1(String str) { StringBuffer s = new StringBuffer(str); System.out.println(s.reverse().toString()); } <pre name="code" class="java"> /** * 字符串倒转 * 不运用StringBuffer */ public static void toReverse2() { String s = "12345"; char[] chars = s.toCharArray(); int j = chars.length - 1; for(int i = 0; i < j/2; i++) { char c = chars[i]; chars[i] = chars[j - i]; chars[j - i] = c; } s = new String(chars); System.out.println(s); }
}
相关文章推荐
- leetcode-Reverse Words in a String 反向输出字符串
- 用递归的思想写编写一个函数reverse_string(char * string)实现字符串反向输出和反向排列
- 问题:求两个字符串的最长公共子串。 要求:输入两个字符串,输出它们的最长公共子串,包括长度。 设计: 设计一个类 String,包括一个 len(字符串长度)和字符串指针 s。另有如下成员函数: ·
- Java中的String字符串倒序输出
- string代替char数组的输入输出以及利用getline每次读取一行字符串
- java用递归实现输入字符串反向输出
- 2381.字符串的操作。string(长度,‘所需输出的内容’)
- 编写一个函数reverse_string(char * string) 实现:将参数字符串中的字符反向排列。
- 编写一个函数reverse_string(char * string) 实现:将参数字符串中的字符反向排列。 要求:不能使用C函数库中的字符串操作函数
- C# Tostring 格式化输出字符串
- java中如何反向输出字符串
- 编写一个函数reverse_string(char * string) 实现:将参数字符串中的字符反向排列。 要求:不能使用C函数库中的字符串操作函数。
- C语言实现 函数reverse_string(char * string) 将参数字符串中的字符反向排列。
- 反向输出字符串
- python 反向输出字符串的方法
- Reverse String反向输出字符串
- 对于输出的字符串进行反向输出(不包括汉字)
- 递归反向输出字符串
- 捕捉 OutputDebugString 输出的字符串
- 将一个string字符串变量分解为字符输出