java程序阅读题,求结果即可(1)
求大家给个结果即可第一题:interfaceComputable{finalintMAX-100;intf(intx);publicabstractintg(intx,i...
求大家给个结果即可
第一题:
interface Computable
{ final int MAX-100;
int f(int x);
public abstract int g(int x,int y);
}
class A implements Computable
{ public int f(int x)
{ return x*x;}
public int g(int x,int y)
{ return x+y;}
}
class B implements Computable
{ public int f(int x)
{ return x*x*x;}
public int g(int x,int y)
{return x*y;}
}
public class Example
{ public static void main(String args[])
{ A a=new A();
B b=new B();
System.out.println(a.MAX);
System.out.println(""+a.f(10)+""+a.g(12,2));
System.out.println(b.MAX);
System.out.println(""+b.f(10)+""+b.g(12,2));
}
}
第二题:
import java.util.regex.*;
public class Example{
public static void main (String args[]){
Pattern p;
Matcher m;
String s1 ="0A1A2A3A4A5A6A7A8A9";
p=Pattern.compile("\\dA\\d");
m=p.matcher(s1);
while(m.find()){
String str=m.group();
System.out.println("从"+m.start()+"到"+m.end()+"匹配模式子序列: "+str);
}
String temp=m.replaceAll("***");
System.out.println(temp);
System.out.println(s1);}
}
第二题的答案有点不明白!! 展开
第一题:
interface Computable
{ final int MAX-100;
int f(int x);
public abstract int g(int x,int y);
}
class A implements Computable
{ public int f(int x)
{ return x*x;}
public int g(int x,int y)
{ return x+y;}
}
class B implements Computable
{ public int f(int x)
{ return x*x*x;}
public int g(int x,int y)
{return x*y;}
}
public class Example
{ public static void main(String args[])
{ A a=new A();
B b=new B();
System.out.println(a.MAX);
System.out.println(""+a.f(10)+""+a.g(12,2));
System.out.println(b.MAX);
System.out.println(""+b.f(10)+""+b.g(12,2));
}
}
第二题:
import java.util.regex.*;
public class Example{
public static void main (String args[]){
Pattern p;
Matcher m;
String s1 ="0A1A2A3A4A5A6A7A8A9";
p=Pattern.compile("\\dA\\d");
m=p.matcher(s1);
while(m.find()){
String str=m.group();
System.out.println("从"+m.start()+"到"+m.end()+"匹配模式子序列: "+str);
}
String temp=m.replaceAll("***");
System.out.println(temp);
System.out.println(s1);}
}
第二题的答案有点不明白!! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询