2014年8月17日 星期日

java程式設計題目---公式計算【矩形面積】

設計一程式,輸入矩形的長和寬(皆為實數),計算面積並列印結果:



  1. import java.util.Scanner;
  2.  
  3. public class ex1
  4. {
  5. public static void main(String[] args)
  6. {
  7. Scanner input =new Scanner(System.in);
  8. //Promt the user for input
  9. //Compute a,b,area
  10. System.out.println("請輸入矩形的長");
  11. double a = input.nextDouble();
  12. System.out.println("請輸入矩形的寬");
  13. double b = input.nextDouble();
  14. double area = a * b ;
  15. //Display results
  16. System.out.println("長=" + a + "寬=" + b +"的矩形面積是"
  17. + area );
  18. }
  19.  
  20. }

沒有留言:

張貼留言

Go(Golang)程式語言 設定GCC

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