2014年12月24日 星期三

java程式設計題目---數字處理【排列組合】

設計一程式,提示使用者輸入兩個整數m、n,接下來從螢幕輸出最小可能(m,n)到最大可能(m,n)的組合。
例如:輸入2,4,輸出:(2,3),(3,4)


  1. import java.util.Scanner;
  2.  
  3. public class C1
  4. {
  5. public static void main(String[] args)
  6. {
  7. Scanner input = new Scanner(System.in);
  8. //提示使用者輸入
  9. System.out.println("請輸入起始整數:");
  10. int m = input.nextInt();
  11. System.out.println("請輸入結束整數:");
  12. int n = input.nextInt();
  13. for(int i = m ; i < n ; i ++ )//控制第1個數
  14. {
  15. for(int a = i + 1 ; a <= n ; a++ )//控制第2個數
  16. {
  17. System.out.println( i + "," + a );
  18. }
  19. }
  20. }
  21. }

1 則留言:

  1. 我不太懂這個題目是甚麼意思?
    可以請你再多解釋一下嗎?

    回覆刪除

Go(Golang)程式語言 設定GCC

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