2014年8月17日 星期日

java程式設計題目---公式計算【圓形面積及周長】

設計一程式,輸入圓形的半徑(為實數),計算面積及周長並列印結果:




  1. import java.util.Scanner;
  2.  
  3. public class ex2
  4. {
  5.  
  6. public static void main(String[] args)
  7. {
  8. Scanner input = new Scanner(System.in);
  9. //Promt the user for input
  10. //Compute area,side
  11. System.out.println("請輸入半徑");
  12. Double r = input.nextDouble();
  13. Double area = r * r * 3.14;
  14. Double side = 2 * r * 3.14;
  15. //Display results
  16. System.out.println("半徑是" + r + ("的圓面積=") + area + (",周長是") + side );
  17. }
  18.  
  19. }

沒有留言:

張貼留言

Go(Golang)程式語言 設定GCC

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