编写程序,颠倒句子中单词的顺序: Enter a sentence: why free software is m
答案:1 悬赏:40 手机版
解决时间 2021-04-18 08:17
- 提问者网友:留有余香
- 2021-04-17 20:51
编写程序,颠倒句子中单词的顺序: Enter a sentence: why free software is m
最佳答案
- 五星知识达人网友:胯下狙击手
- 2021-04-17 21:19
这不是都有提示了么...
char[] charStr = "Enter a sentence: why free software is more important now than ever before?
Reversal of sentence: before ever than now important more is software free why?".toCharArray();
List strList = new ArrayList();
String one= "";//保存每一个单词
for(int i =0;i if(charStr[i] == ',' ||charStr[i] == '.'||charStr[i] == '?'||charStr[i] == '!'){
list.add(one)
one = "";
} else{
one +=charStr[i];
}
}
String all = "";
for(int i =strList.size()-1;i>=0;i--){
all += strList.get(i);//倒着取list里的值
}
System.out.println(all);
不按提示来,简单点是(str就是字符串):
byte[] b = str.getBytes();
for(int i =0;i byte b1 = b[i];
b[i]=b[b.length-1-i];
b[b.length-1-i] = bi;
}
System.out.println(new String(b));
char[] charStr = "Enter a sentence: why free software is more important now than ever before?
Reversal of sentence: before ever than now important more is software free why?".toCharArray();
List
String one= "";//保存每一个单词
for(int i =0;i
list.add(one)
one = "";
} else{
one +=charStr[i];
}
}
String all = "";
for(int i =strList.size()-1;i>=0;i--){
all += strList.get(i);//倒着取list里的值
}
System.out.println(all);
不按提示来,简单点是(str就是字符串):
byte[] b = str.getBytes();
for(int i =0;i
b[i]=b[b.length-1-i];
b[b.length-1-i] = bi;
}
System.out.println(new String(b));
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯