java的一道题目
输入字符串“theyarestudent”输出“studentarethey”,要怎么做呢?...
输入字符串“they are student”输出“student are they”,要怎么做呢?
展开
4个回答
2014-04-16
展开全部
按空格拆成数组,反序输出不就完了
追问
其实我想到假设是a b c这样的形式就好办,我就是不知道怎么把那个单词变成一个数组的元素,你能写个代码吗?
追答
有人已经替我回答了....
展开全部
import javax.swing.JOptionPane;public class ReverseString {
public static void main (String args[]){
String originalString;
String resultString = "";
originalString = JOptionPane.showInputDialog("Please input a String: ");
char[] charArray = originalString.toCharArray();
for (int i=charArray.length-1; i>=0; i--){
resultString += charArray[i];
}
JOptionPane.showMessageDialog(null, resultString, "Reverse String", JOptionPane.INFORMATION_MESSAGE);
}
}
import javax.swing.JOptionPane;
public class ReverseString {
public static void reverseString (String str){
if (str.length() == 1){
System.out.print(str);
}
else{
String subString1 = str.substring(0, str.length()-1);
String subString2 = str.substring(str.length()-1);
System.out.print(subString2);
reverseString (subString1);
}
}
public static void main (String args[]){
String originalString;
originalString = JOptionPane.showInputDialog("Please input a String: ");
reverseString (originalString);
}
}
public class ReverseString {
public static void reverseString (String str){
StringBuffer stringBuffer = new StringBuffer (str);
System.out.print(stringBuffer.reverse());
}
public static void main (String args[]){
String originalString;
originalString = JOptionPane.showInputDialog("Please input a String: ");
reverseString (originalString);
}
}
public static void main (String args[]){
String originalString;
String resultString = "";
originalString = JOptionPane.showInputDialog("Please input a String: ");
char[] charArray = originalString.toCharArray();
for (int i=charArray.length-1; i>=0; i--){
resultString += charArray[i];
}
JOptionPane.showMessageDialog(null, resultString, "Reverse String", JOptionPane.INFORMATION_MESSAGE);
}
}
import javax.swing.JOptionPane;
public class ReverseString {
public static void reverseString (String str){
if (str.length() == 1){
System.out.print(str);
}
else{
String subString1 = str.substring(0, str.length()-1);
String subString2 = str.substring(str.length()-1);
System.out.print(subString2);
reverseString (subString1);
}
}
public static void main (String args[]){
String originalString;
originalString = JOptionPane.showInputDialog("Please input a String: ");
reverseString (originalString);
}
}
public class ReverseString {
public static void reverseString (String str){
StringBuffer stringBuffer = new StringBuffer (str);
System.out.print(stringBuffer.reverse());
}
public static void main (String args[]){
String originalString;
originalString = JOptionPane.showInputDialog("Please input a String: ");
reverseString (originalString);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public static void main(String[] args) {
String ceshi="they are student";
String[] tas = ceshi.split(" ");
String result=tas[2]+" "+tas[1]+" "+tas[0];
System.out.println(result);
}
不知道是不是你想要的
String ceshi="they are student";
String[] tas = ceshi.split(" ");
String result=tas[2]+" "+tas[1]+" "+tas[0];
System.out.println(result);
}
不知道是不是你想要的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public static void main(String[] args) {
String str="they are student";
String[] st=str.split(" ");
for (int i = st.length-1; i >= 0; i--) {
System.out.print(st[i]+" ");
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询