JAVA中如何用while循环实现一个整数的倒序输出,例如输入12345,输出54321

2024-10-31 12:54:30
推荐回答(3个)
回答1:

int i = 12343465;
int m = 0;
while (i != 0) {
m =i%10;
System.out.print(m);
i = i/10;
}

回答2:

String str = "123456";
int index = str.length();
while (index != 0) {
System.out.print(str.substring(index - 1, index));
index--;
}

回答3:

public static void reverseString (String str){
StringBuffer stringBuffer = new StringBuffer (str);
System.out.print(stringBuffer.reverse());
}

把你的整形变为字符串,巧颂通过reverse方法倒渣颂序输如宽郑出提交回答