回覆列表
-
1 # ltaht18438
-
2 # 藍風24
#include
void main()
{
int n,s=0;
printf("請輸入一個整數:");
scanf("%d",&n);
while(n!=0)
{
s=s*10+n%10;
n/=10;
}
printf("%d",s);
}
#include
void main()
{
int n,s=0;
printf("請輸入一個整數:");
scanf("%d",&n);
while(n!=0)
{
s=s*10+n%10;
n/=10;
}
printf("%d",s);
}
程式碼如下:import java.util.Scanner;public class ReverseNumber { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("請輸入一個整數:"); int num = scanner.nextInt(); StringBuilder stringBuilder = new StringBuilder(); String reverseStr = stringBuilder.append(num).reverse().toString(); System.out.println(reverseStr); //如果想要整型,再轉換一次 int reverseNum = Integer.valueOf(reverseStr);// System.out.println(reverseNum); }}