发布网友
共3个回答
热心网友
public class Demo1
{
public static void main(String []args)throws IOException
{
Square a=new Square(1.1f,1.1f);
a.GetResults(a);
}
}
class Square
{
float width,length;
Square(float w,float l)
{
width=w;
length=l;
}
public void GetResults(Square s)
{
System.out.println("面积为:"+s.width*s.length);
}
}
感觉有点多此一举。。。。。为什么要再将Square 传过去呢;
public void GetResults()
{
System.out.println("面积为:"+width*length);
}
直接这样不可以吗
热心网友
参数类型要一致啊,下面的那个类改下就行,还有那个异常不要抛
class Square
{
Square s;
float width,length;
Square(float w,float l)
{
width=w;
length=l;
}
public void GetResults(float width2,float length2)
{
System.out.println("面积为:"+s.width*s.length);
}
}
热心网友
public class Demo1
{
public static void main(String []args)
{
try{
Square a=new Square(1.1f,1.1f);
a.GetResults();
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
}
class Square
{
float width,length;
Square(float w,float l)
{
width=w;
length=l;
}
public void GetResults()
{
System.out.println("面积为:"+width*length);
}
}