2014年12月23日 星期二

java程式設計題目---數字處理【三位數拆解重組】

設計一程式,提示使用者輸入一個三位數整數,計算出此數值的每個位數後,將所有位數以相反順序重新組合成整數值,並將結果列印出。
例如:輸入 123,輸出321


  1. import java.util.Scanner;
  2.  
  3. public class C1
  4. {
  5.  
  6. public static void main(String[] args)
  7. {
  8. Scanner input = new Scanner(System.in);
  9. System.out.println("請入一個三位數:");
  10. int a = input.nextInt();
  11. int b = a / 100;
  12. int c = ( a - b * 100 ) / 10;
  13. int d = a - 100 * b - 10 * c;
  14. System.out.println("結果為:" + d + c + b);
  15. }
  16.  
  17. }

沒有留言:

張貼留言

Go(Golang)程式語言 設定GCC

下載MSYS2:  https://www.msys2.org/ 安裝 程式開始執行後輸入: pacman -Syu y y 在安裝目錄底下找到msys2.exe,雙擊執行 輸入指令: pacman -Su pacman -S --needed base-devel mingw-...