java 逆序输出问题
如果是数字的话,可以通过以下方式逆序输出:
int i = 12343465;
int m = 0;
while (i != 0) {
m =i%10;
System.out.print(m);
i = i/10;
}
如果是字符串的话,可以通过以下方式逆序输出:
public class reverseTest {
public static void main(String[] args) {
String originalString = "abcdefg";
StringBuffer stringBuffer = new StringBuffer(originalString);
System.out.println(stringBuffer.reverse());
}
}
字符串的话,还可以通过以下方式逆序输出:
public class javatest {
public static void main(String[] args) {
String originalString = "abcdefg";
String resultString = "";
char[] charArray = originalString.toCharArray();
for (int i = charArray.length-1; i>=0; i--){
resultString +=charArray[i];
}
System.out.println(resultString);
}
}
2013-09-08
Scanner s = new Scanner(System.in);
for(int i=0;i<5;i++)
list.add(s.nextLine());
for(int i=4;i>=0;i--)
System.out.println(list.get(i));
Scanner s = new Scanner(System.in);
for(int i=0;i<5;i++)
list.add(s.nextLine());
for(int i=4;i>=0;i--)
System.out.println(list.get(i));