返回首页

JAVA编程题目,共四题,做其中一题就够了,

63 2023-05-26 06:42 admin

好了,你测试一下咯!

public interface ShapeArea {//定义ShapeArea接口

public double getArea();//double getArea( ):求一个形状的面积

public double getPerimeter();//启袜 Double getPerimeter( ):求一个肢埋形状的周长。

}

public class MyTriangle implements ShapeArea {

double x,y,z,s;//x,y,z :double型,表示三角形的三条边

public MyTriangle(double x, double y, double z) {//方法:MyTriangle(double x, double y, double z):构造函数,给三条边和s赋值;

this.x = x;

this.y = y;

this.z = z;

this.s = (x+y+z)/2;

}

@Override

public double getArea() {

return Math.sqrt(this.s*(this.s-this.x)*(this.s-this.y)*(this.s-this.z));

}

@Override

public double getPerimeter() {

return (x+y+z);

}

@Override

public String toString() {

System.out.print(此三角形的面积和周悄饥激长为:);

return this.getArea()+、+this.getPerimeter();

}

}

public class Test {//测试类

public static void main(String[] args) {

MyTriangle myTriangle = new MyTriangle(3, 4, 5);

System.out.println(myTriangle);

}

}

额热风风热二恶突然人员突然一天

import java.util.ArrayList;

import java.util.Collection;

public class StringUtils {

public static Integer[] positions(String shortStr,String longStr){

Collection<Integer> positions = new ArrayList<Integer>();

int index = 0;

while((index=longStr.indexOf(shortStr, index)+1)!=0){

positions.add(index-1);

}

return positions.toArray(new Integer[positions.size()]);

}

public static boolean isHuiWen(String str){

byte[] bytes = str.getBytes();

for(int i=0;i<bytes.length/2;i++){

if(bytes[i]==bytes[bytes.length-i-1]){

continue;

}else{

return false;

}

}

return true;

}

public static String getName(String email){

return email.substring(0, email.indexOf(@));

}

}

e