Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. /*
  2. 1. 宣告兩 int 變數, 印出其和、積、差、商
  3. 2. 宣告兩 double 變數, 印出其和、積、差、商
  4. */
  5. public class HW2 {
  6. public static void main(String[] args) {
  7. //宣告int 並指定值
  8. int a = 300;
  9. int b = 200;
  10. System.out.println(int a + int b); // 和
  11. System.out.println(int a * int b); // 積
  12. System.out.println(int a - int b); // 差
  13. System.out.println(int a / int b); // 商
  14. //宣告double 並指定值
  15. double c = 30.5;
  16. double d = 20.5;
  17. System.out.println(double c + double d); // 和
  18. System.out.println(double c * double d); // 積
  19. System.out.println(double c - double d); // 差
  20. System.out.println(double c / double d); // 商
  21.  
  22.  
  23.  
  24. }
  25. }`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement