尝试完成我的第一年comp课程的作业。到目前为止,一切都没问题,但我无法解决这个问题。我想知道是否有人可以在这里帮忙?我尝试将变量改为双打,显然它没有用。
import java.util.Scanner;
public class CellPhoneProgram {
public static Scanner keyboard = new Scanner(System.in);
//declare x and y coordinates for each city
public static double xa = 100, xb = 100, xc = 340, xd = 230, ya = 360, yb = 360, yc = 250, yd = 140;
public static int getRange(int city) {
int range = 0;
System.out.println("What is the maximum distance (in km) from the center of City " + city + " that you may travel without losing service?");
range = keyboard.nextInt();
return range;
}
/* ERROR OCCURS HERE */
public static double distance(double xf, double xi, double yf, double yi) {
double distance = 0;
distance = Math.sqrt((Math.pow(xf - xi)) - (Math.pow(yf - xi)));
return distance;
}
public static void main(String[] args) {
int city1, city2, city3, city4;
double distance1, distance2, distance3;
System.out.println("Welcome to the Cell Phone Service Program, where you enter the range of service from four cities," +
" and we calculate whether or not you lose service.");
//get range from function
city1 = getRange(1);
city2 = getRange(2);
city3 = getRange(3);
city4 = getRange(4);
System.out.println(city3);
//calculate distances from cities
distance1 = distance(xb, xa, yb, ya);
distance2 = distance(xc, xb, yc, yb);
distance1 = distance(xd, xc, yd, yc);
System.out.println(distance1);
}
}

在这里查看错误:
File: C:\Users\Katie\Documents\Homework\CellPhoneProgram.java [line: 16]
Error: method pow in class java.lang.Math cannot be applied to given types;
required: double,double
found: double
reason: actual and formal argument lists differ in length
File: C:\Users\Katie\Documents\Homework\CellPhoneProgram.java [line: 16]
Error: method pow in class java.lang.Math cannot be applied to given types;
required: double,double
found: double
reason: actual and formal argument lists differ in length

这段代码肯定还在进行中,对于混乱和不完整的代码以及所有这一切感到抱歉。
答案 0 :(得分:0)
Math.pow()需要两个参数而不是一个。我猜你想提高到第二个权力,所以第二个参数应该是2.
memset
请参阅http://docs.oracle.com/javase/7/docs/api/java/lang/Math.html#pow%28double,%20double%29