【发布时间】:2014-03-18 09:37:09
【问题描述】:
import java.util.Scanner;
import java.lang.Math;
public class Assignment1{
//instance variables
double a;
double b;
double c;
// method
public double hypot(double x, double y){
x = x*x;
y = y*y;
double z = x+y;
z = Math.sqrt(z);
return z;
}
// constructor
public Assignment1(double a , double b, double c){
this.a = a;
this.b = b;
this.c = c;
}
public static void main(String [] args){ // execution starts from here
Assignment1 obj = new Assignment1(a,b,c);
Scanner in = new Scanner(System.in);
System.out.println("Enter the values to compute the pythagoras theorem");
obj.a = in.nextDouble();
obj.b = in.nextDouble();
obj.c = hypot(a,b);
System.out.println("The hypot is"+ c);
}
}
这段代码有什么问题...我正在创建对象...那么它应该可以正常工作!不是吗???
【问题讨论】:
-
对我来说看起来像是一项编程任务...也许您正试图在静态方法中使用非静态字段?
-
使用IDE。
标签: java object methods constructor static