import java.util.*;
interface One
{
int someMethod(int a, int b);
}
interface Two
{
int anotherMethod(String s);
}
interface Three
{
String oneMoreMethod(int a, int b);
}
// Interface which extends three other interfaces
//
interface MultipleInterface extends One, Two, Three
{
void myMethod();
}
class Implement_Interface implements MultipleInterface
{
public int someMethod(int a, int b)
{
return a + b;
}
// 兩數相加 ;
public String oneMoreMethod(int a, int b)
{ // 傳入兩數相乘,判斷是否>20,是 傳回
return (a * b) > 20 ? "Yes, you are right " + (a * b) : "No, you are worng " + (a * b);
};
public int anotherMethod(String s)
{
return s.length();
}// 字串長度計算 } ;
public void myMethod()
{ // 輸出 Do nothing at this moment } ;
System.out.println("Do nothing at this moment");
}
}
public class Java_CH6_HW1
{
public static void main(String[] args)
{
int m, n, add1 = 0, sub1, mul1, div1;
String s1 = "Today";
Scanner sc = new Scanner(System.in);
System.out.println(" Please enter two integer number ");
m = sc.nextInt();
n = sc.nextInt();
Implement_Interface im = new Implement_Interface();
s1 = im.oneMoreMethod(m, n);
System.out.println("The addition is:" + im.someMethod(m, n));
System.out.println("The string:" + s1 + " The string length:" + im.anotherMethod(s1));
System.out.println(" Please enter a string ");
Scanner sc1 = new Scanner(System.in);
s1 = sc1.nextLine();
System.out.println("The string:" + s1 + " The string length:" + im.anotherMethod(s1));
im.myMethod();
}
}
留言
張貼留言