Created
September 23, 2012 14:05
-
-
Save jipeigang/3771293 to your computer and use it in GitHub Desktop.
作业4.1.2将一个不以0开头的数字串逆序输出
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class H0040102ChangeNum{ | |
| public static void main(String[] args){ | |
| System.out.println("请输入要逆转的整数串"); | |
| java.util.Scanner input = new java.util.Scanner(System.in); | |
| long num = input.nextLong(); | |
| String str = ""; | |
| str += num; | |
| long midnum; | |
| String changedNum = ""; | |
| while(num > 0){ | |
| midnum = num; | |
| midnum = midnum % 10; | |
| changedNum += midnum; | |
| num = (num - midnum) / 10; | |
| } | |
| System.out.println("逆转后的数字串为:" + changedNum); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment