将字符串"hello world,hello java"输出为"java hello,world hello"。怎么用java编程实现
展开全部
倒是可以鉴戒一下这个例子:
import java.util.Arrays;
public class Test {
public static void main(String[] args) {
String s = "123456789";
StringBuffer sb = new StringBuffer();
char[] arr = s.toCharArray();
System.out.println("拆分后:" + Arrays.toString(arr));
int len = s.length();
for (int b = 0; b < s.length(); b++) {
sb.append(arr[len - b - 1]);
}
String result = sb.toString();
System.out.println("倒着输出:" + result);
}
}
import java.util.Arrays;
public class Test {
public static void main(String[] args) {
String s = "123456789";
StringBuffer sb = new StringBuffer();
char[] arr = s.toCharArray();
System.out.println("拆分后:" + Arrays.toString(arr));
int len = s.length();
for (int b = 0; b < s.length(); b++) {
sb.append(arr[len - b - 1]);
}
String result = sb.toString();
System.out.println("倒着输出:" + result);
}
}
展开全部
String str = "hello world,hello java";
String result = "";
String[] strs = str.split(",");
String[] strworld = strs[0].split(" ");
String[] strjava = strs[1].split(" ");
result = strjava[1]+" "+strjava[0]+","+strworld[1]+" "+strworld[0];
String result = "";
String[] strs = str.split(",");
String[] strworld = strs[0].split(" ");
String[] strjava = strs[1].split(" ");
result = strjava[1]+" "+strjava[0]+","+strworld[1]+" "+strworld[0];
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询