Java input the number of words, reverse output this number
Source: Internet
Author: User
Package Demo;import java.util.scanner;/** * Input The number of words, reverse output this number * Do not use the inverse function * @author Tseng */public class B {public static void Main (string[] args) {Scanner sc = new Scanner (system.in); System.out.println ("Please enter an integer:"); Long Num=sc.nextlong (); getwhile (num); getString (num);} /** * @param num */public static void getwhile (Long num) {LONG ret = 0;//in-reverse number while (true) {Long n = num%10;/ /Remove the number on the lowest digit RET = ret*10 + n;//in turn the reverse store gets the inverted number num = num/10;//drop-down if (num = = 0) {break;}} System.out.println ("Inverted number is: (Take Low)" +ret);} /** * Using the inversion of the digital spin string * @param n1 */public static void getString (Long num) {String SS = string.valueof (num), s3= ""; for (int i=ss . Length () -1;i>=0;i--) {s3 + = Ss.charat (i);} Long n = long.parselong (S3); System.out.println ("Inverse number is: (string subscript)" + N);}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.