Java 编写求三角形长度C的程序
考虑到a边和B边的长度,我正试图编写一个程序来寻找直角三角形的C边。到目前为止,我得到的是:Java 编写求三角形长度C的程序,java,eclipse,Java,Eclipse,考虑到a边和B边的长度,我正试图编写一个程序来寻找直角三角形的C边。到目前为止,我得到的是: /* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Math { pub
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Math
{
public static void main (String[] args) throws java.lang.Exception
{
// Scanner scan = new scanner(system.in);
int a, b, c;
int length c; c = sqrt(a^(2)+b^(2))
System.out.println("Length of side a?");
a = scan.nextdouble();
System.out.println("Length of side b?");
b = scan.nextdouble();
c = math.sqrt(a^(2)+b^(2));
System.out.print("The length of side C is");
System.out.println(c+ "units.");
scan.close();
}
}
Eclipse告诉我有一个参数错误,但我不知道应该怀疑什么。有什么建议吗?我知道这很简单,我觉得解决方案就在我面前 更改此
int长度c;c=sqrt(a^(2)+b^(2))
toint-length代码>更改此整数长度c;c=sqrt(a^(2)+b^(2))
toint-length代码>更改此整数长度c;c=sqrt(a^(2)+b^(2))
toint-length代码>更改此整数长度c;c=sqrt(a^(2)+b^(2))
toint-length代码>符号与XOR相同。它并不意味着“对……的力量”。您需要使用
Math.pow(a, 2) + Math.pow(b, 2);
或
^符号与XOR相同。它并不意味着“对……的力量”。您需要使用
Math.pow(a, 2) + Math.pow(b, 2);
或
^符号与XOR相同。它并不意味着“对……的力量”。您需要使用
Math.pow(a, 2) + Math.pow(b, 2);
或
^符号与XOR相同。它并不意味着“对……的力量”。您需要使用
Math.pow(a, 2) + Math.pow(b, 2);
或
有很多错误。。。这是工作版本:
import java.util.*;
import java.lang.*;
import java.io.*;
class Math
{
public static void main (String[] args) throws java.lang.Exception {
Scanner scan = new Scanner(System.in); // this had errors
double a, b, c; // doubles are better for division,
// unless you want imprecise results
System.out.println("Length of side a?");
a = scan.nextDouble(); // note the case in the method name, this was wrong
System.out.println("Length of side b?");
b = scan.nextDouble(); // same here
c = java.lang.Math.sqrt(java.lang.Math.pow(a,2) + java.lang.Math.pow(b,2));
System.out.print("The length of side C is ");
System.out.println(c + "units.");
scan.close();
}
}
由于您将类命名为Math,因此必须为sqrt和pow使用完整的java.lang.Math前缀。有很多错误。。。这是工作版本:
import java.util.*;
import java.lang.*;
import java.io.*;
class Math
{
public static void main (String[] args) throws java.lang.Exception {
Scanner scan = new Scanner(System.in); // this had errors
double a, b, c; // doubles are better for division,
// unless you want imprecise results
System.out.println("Length of side a?");
a = scan.nextDouble(); // note the case in the method name, this was wrong
System.out.println("Length of side b?");
b = scan.nextDouble(); // same here
c = java.lang.Math.sqrt(java.lang.Math.pow(a,2) + java.lang.Math.pow(b,2));
System.out.print("The length of side C is ");
System.out.println(c + "units.");
scan.close();
}
}
由于您将类命名为Math,因此必须为sqrt和pow使用完整的java.lang.Math前缀。有很多错误。。。这是工作版本:
import java.util.*;
import java.lang.*;
import java.io.*;
class Math
{
public static void main (String[] args) throws java.lang.Exception {
Scanner scan = new Scanner(System.in); // this had errors
double a, b, c; // doubles are better for division,
// unless you want imprecise results
System.out.println("Length of side a?");
a = scan.nextDouble(); // note the case in the method name, this was wrong
System.out.println("Length of side b?");
b = scan.nextDouble(); // same here
c = java.lang.Math.sqrt(java.lang.Math.pow(a,2) + java.lang.Math.pow(b,2));
System.out.print("The length of side C is ");
System.out.println(c + "units.");
scan.close();
}
}
由于您将类命名为Math,因此必须为sqrt和pow使用完整的java.lang.Math前缀。有很多错误。。。这是工作版本:
import java.util.*;
import java.lang.*;
import java.io.*;
class Math
{
public static void main (String[] args) throws java.lang.Exception {
Scanner scan = new Scanner(System.in); // this had errors
double a, b, c; // doubles are better for division,
// unless you want imprecise results
System.out.println("Length of side a?");
a = scan.nextDouble(); // note the case in the method name, this was wrong
System.out.println("Length of side b?");
b = scan.nextDouble(); // same here
c = java.lang.Math.sqrt(java.lang.Math.pow(a,2) + java.lang.Math.pow(b,2));
System.out.print("The length of side C is ");
System.out.println(c + "units.");
scan.close();
}
}
由于您将类命名为Math,因此必须为sqrt和pow使用完整的java.lang.Math前缀。removeint length c代码>
第一个length未使用,并且已声明c。删除int length c代码>
第一个length未使用,并且已声明c。删除int length c代码>
第一个length未使用,并且已声明c。删除int length c代码>
首先,length没有使用,而且c已经声明。我不知道你怎么会犯这么多错误
这是一个工作代码
import java.util.Scanner;
public class Lame {
/**
* @param args
*/
public static void main(String[] args) {
double a, b, c;
Scanner scan = new Scanner(System.in);
System.out.println("Length of side a?");
a = scan.nextDouble();
System.out.println("Length of side b?");
b = scan.nextDouble();
c = Math.sqrt((a*a + b*b));
System.out.print("The length of side C is");
System.out.println(c+ "units.");
}
}
一些提示。注意你的资本化。Java区分大小写。
扫描器和扫描器在java中不是一回事!(类大写,而函数不大写)
Java不会自动转换类型
无法设置a=scan.nextDouble():因为它将返回双精度而不是int。
(如果要将双精度转换为int,必须自己进行)
Java中没有电源符号^。您需要使用一个pow()函数,或者只需执行一个变量乘以自身,比如*a
把你的班名改成数学
尝试谷歌的东西,做很多书中的练习,只是处理代码。过一段时间,你就会开始理解事情了 我不知道你怎么会犯这么多错误
这是一个工作代码
import java.util.Scanner;
public class Lame {
/**
* @param args
*/
public static void main(String[] args) {
double a, b, c;
Scanner scan = new Scanner(System.in);
System.out.println("Length of side a?");
a = scan.nextDouble();
System.out.println("Length of side b?");
b = scan.nextDouble();
c = Math.sqrt((a*a + b*b));
System.out.print("The length of side C is");
System.out.println(c+ "units.");
}
}
一些提示。注意你的资本化。Java区分大小写。
扫描器和扫描器在java中不是一回事!(类大写,而函数不大写)
Java不会自动转换类型
无法设置a=scan.nextDouble():因为它将返回双精度而不是int。
(如果要将双精度转换为int,必须自己进行)
Java中没有电源符号^。您需要使用一个pow()函数,或者只需执行一个变量乘以自身,比如*a
把你的班名改成数学
尝试谷歌的东西,做很多书中的练习,只是处理代码。过一段时间,你就会开始理解事情了 我不知道你怎么会犯这么多错误
这是一个工作代码
import java.util.Scanner;
public class Lame {
/**
* @param args
*/
public static void main(String[] args) {
double a, b, c;
Scanner scan = new Scanner(System.in);
System.out.println("Length of side a?");
a = scan.nextDouble();
System.out.println("Length of side b?");
b = scan.nextDouble();
c = Math.sqrt((a*a + b*b));
System.out.print("The length of side C is");
System.out.println(c+ "units.");
}
}
一些提示。注意你的资本化。Java区分大小写。
扫描器和扫描器在java中不是一回事!(类大写,而函数不大写)
Java不会自动转换类型
无法设置a=scan.nextDouble():因为它将返回双精度而不是int。
(如果要将双精度转换为int,必须自己进行)
Java中没有电源符号^。您需要使用一个pow()函数,或者只需执行一个变量乘以自身,比如*a
把你的班名改成数学
尝试谷歌的东西,做很多书中的练习,只是处理代码。过一段时间,你就会开始理解事情了 我不知道你怎么会犯这么多错误
这是一个工作代码
import java.util.Scanner;
public class Lame {
/**
* @param args
*/
public static void main(String[] args) {
double a, b, c;
Scanner scan = new Scanner(System.in);
System.out.println("Length of side a?");
a = scan.nextDouble();
System.out.println("Length of side b?");
b = scan.nextDouble();
c = Math.sqrt((a*a + b*b));
System.out.print("The length of side C is");
System.out.println(c+ "units.");
}
}
一些提示。注意你的资本化。Java区分大小写。
扫描器和扫描器在java中不是一回事!(类大写,而函数不大写)
Java不会自动转换类型
无法设置a=scan.nextDouble():因为它将返回双精度而不是int。
(如果要将双精度转换为int,必须自己进行)
Java中没有电源符号^。您需要使用一个pow()函数,或者只需执行一个变量乘以自身,比如*a
把你的班名改成数学
尝试谷歌的东西,做很多书中的练习,只是处理代码。过一段时间,你就会开始理解事情了 它的日食其实并不重要。java程序在任何其他IDE中看起来都一样,去掉行int长度c;c=sqrt(a^(2)+b^(2)),然后再次运行程序。clipse告诉我有一个参数错误,但我不知道该怀疑什么。-我会怀疑Eclipse标记的那行包含错误。您的代码有太多问题,无法在单个答案中涵盖。一个小列表:math
应该是math
,^