Java_CH6_HW1


  1. import java.util.*;
  2. interface One
  3. {
  4. int someMethod(int a, int b);
  5. }
  6. interface Two
  7. {
  8. int anotherMethod(String s);
  9. }
  10. interface Three
  11. {
  12. String oneMoreMethod(int a, int b);
  13. }
  14. // Interface which extends three other interfaces
  15. //
  16. interface MultipleInterface extends One, Two, Three
  17. {
  18. void myMethod();
  19. }
  20. class Implement_Interface implements MultipleInterface
  21. {
  22. public int someMethod(int a, int b)
  23. {
  24. return a + b;
  25. }
  26. // 兩數相加 ;
  27. public String oneMoreMethod(int a, int b)
  28. { // 傳入兩數相乘,判斷是否>20,是 傳回
  29. return (a * b) > 20 ? "Yes, you are right " + (a * b) : "No, you are worng " + (a * b);
  30. };
  31. public int anotherMethod(String s)
  32. {
  33. return s.length();
  34. }// 字串長度計算 } ;
  35. public void myMethod()
  36. { // 輸出 Do nothing at this moment } ;
  37. System.out.println("Do nothing at this moment");
  38. }
  39. }
  40. public class Java_CH6_HW1
  41. {
  42. public static void main(String[] args)
  43. {
  44. int m, n, add1 = 0, sub1, mul1, div1;
  45. String s1 = "Today";
  46. Scanner sc = new Scanner(System.in);
  47. System.out.println(" Please enter two integer number ");
  48. m = sc.nextInt();
  49. n = sc.nextInt();
  50. Implement_Interface im = new Implement_Interface();
  51. s1 = im.oneMoreMethod(m, n);
  52. System.out.println("The addition is:" + im.someMethod(m, n));
  53. System.out.println("The string:" + s1 + " The string length:" + im.anotherMethod(s1));
  54. System.out.println(" Please enter a string ");
  55. Scanner sc1 = new Scanner(System.in);
  56. s1 = sc1.nextLine();
  57. System.out.println("The string:" + s1 + " The string length:" + im.anotherMethod(s1));
  58. im.myMethod();
  59. }
  60. }

留言

這個網誌中的熱門文章

C# 井字遊戲