1、请写一Java类,实现MyMath接口,并实现相关功能。

2025-01-07 08:03:28
推荐回答(3个)
回答1:

//1
public class Test1 implements MyMath{
public float add(float x,float y){
return x+y;
}
public float multiply (float x,float y){
return x*y;
}
}
//第2个
public class Test2{

public static void main(String[] args) {
Vector v = new Vector();
v.add("a");
v.add("b");
// 从Vector中删除元素
v.remove("a"); // 删除指定内容的元素
v.remove(0); // 按照索引号删除元素
// 遍历Vector中的元素
for (int i = 0; i < v.size(); i++) {
System.out.println(v.get(i));
}
}
}
//第三个
public class Test3{
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
System.out.println("现在是" + sdf.format(cal.getTime()) + "星期" + cal.getTime().getDay());
}
}

回答2:

public class MMath implement MyMath{
public float add(float x,float y) {
return x+y;//x和y相加
}
public float multiply (float x,float y) {
return x*y;//x和y相乘
}
}

回答3:

1.
public class TestMyMath implements MyMath{
public float add(float x,float y){
return x+y;
}
public float multiply (float x,float y){
return x*y;
}
}
2.
public class TestVector{
public static void main(String[] args) {
Vector vector = new Vector();
v.add("a1");
v.add("a2");
// 从Vector中删除元素
v.remove("a1"); // 删除指定内容的元素
v.remove(0); // 按照索引号删除元素
// 遍历Vector中的元素
for (int i = 0; i < v.size(); i++) {
System.out.println(v.get(i));
}
}
}
3.
public class TestTime{
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
System.out.println("现在是" + sdf.format(cal.getTime()) + "星期" + cal.getTime().getDay());
}
}