求教大神 方法声明无效:需要返回类型 是啥意思?

MeterO_ 2016-10-30 06:50:27
import java.util.*;
public class Experiment2{
public static void main (String[] args){
Triangle t1 = new Triangle(1,0,0,1,0,0) ;
t1.show();
}
private boolean isTriangle = false;
private double l1 = 0.0d;
private double l2 = 0.0d;
private double l3 = 0.0d;
private double l = 0.0d;
private double s = 0.0f;
public Triangle(int x1,int y1,int x2,int y2,int x3,int y3)
{

Point a = new Point(x1,y1);
Point b = new Point(x2,y2);
Point c = new Point(x3,y3);
l1 = getLength(a,b);
l2 = getLength(a,c);
l3 = getLength(b,c);
getLong();
getArea();
}
private getLength(Point a,Point b){
double sub1 = 0.0d;
double sub2 = 0.0d;
sub1 = a.x>b.x?a.x - b.x: a.x - b.x;
sub2 = a.y>b.y?a.y - b.y: a.y - b.y;
double h = sub1*sub1+sub2*sub2;
return Math.sqrt(h);
}
private void getLength()
{
l = a+b+c;
}
public void getArea();
{
double p = (l1 + l2 + l3)/2;
s= Math.sqrt(p*(p-l1)*(p-l2)*(p-l3));
}
public void show();
{
System.out.println("First side is :"+l1);
System.out.println("Second side is :"+l2);
System.out.println("Third side is :"+l3);
System.out.println("The Long is :"+l);
System.out.println("The area is :"+s);
}
private class Point{
public int x = 0;
public int y = 0;
public Point(int px,int py){
x = px;
y = py;
}
}
}
这个要如何修改
...全文
534 9 打赏 收藏 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
___d 2016-10-31
  • 打赏
  • 举报
回复
private double getLength(Point a,Point b){ double sub1 = 0.0d; double sub2 = 0.0d; sub1 = a.x>b.x?a.x - b.x: a.x - b.x; sub2 = a.y>b.y?a.y - b.y: a.y - b.y; double h = sub1*sub1+sub2*sub2; return Math.sqrt(h); }
月明星稀灬 2016-10-31
  • 打赏
  • 举报
回复
方法没有返回类型,void表示无返回 public String getStr(){ return ""; } 返回字符串
MeterO_ 2016-10-31
  • 打赏
  • 举报
回复
引用 4 楼 student_zzp 的回复:
没有返回类型,应该是private double getLength(Point a,Point b)
现在是这样的
MeterO_ 2016-10-31
  • 打赏
  • 举报
回复
引用 4 楼 student_zzp 的回复:
没有返回类型,应该是private double getLength(Point a,Point b)

改好了。。。。
小灰狼 2016-10-31
  • 打赏
  • 举报
回复
编译器提示已经很清楚了,方法定义要有返回类型 看看基础书,怎么声明一个方法 注意是最基础书的,讲语法的,不是什么编程思想
喵爱旺 2016-10-30
  • 打赏
  • 举报
回复
没有返回类型,应该是private double getLength(Point a,Point b)
MeterO_ 2016-10-30
  • 打赏
  • 举报
回复
。。。。。有人理我一下吗
MeterO_ 2016-10-30
  • 打赏
  • 举报
回复
!!!!!!!!!!!
MeterO_ 2016-10-30
  • 打赏
  • 举报
回复
!!!!!!!!!!!!!

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧