# 2019-10-14 上課範例 ## PT2 ### 範例一 (錯誤) ```java= import java.util.Scanner; public class PT2 { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("請輸入三角型的底:"); int base = in.nextInt(); System.out.println("請輸入三角型的高:"); int heigh = in.nextInt(); in.close(); double area = (base * heigh) / 2; System.out.println("三角型面積:" + area); } } ``` ### 範例二 ```java= import java.util.Scanner; public class PT2 { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("請輸入三角型的底:"); int base = in.nextInt(); System.out.println("請輸入三角型的高:"); int heigh = in.nextInt(); in.close(); double area = (base * heigh) / 2.0; System.out.println("三角型面積:" + area); } } ``` ### 範例三 ```java= import java.util.Scanner; public class PT2 { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("請輸入三角型的底:"); int base = in.nextInt(); System.out.println("請輸入三角型的高:"); int heigh = in.nextInt(); in.close(); double area = (double)(base * heigh) / 2; System.out.println("三角型面積:" + area); } } ``` ###### tags: `Java計算機程式設計` `108-1`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up