在主要课程中获得错误请解决。 [英] Getting error in main class please resolve.
本文介绍了在主要课程中获得错误请解决。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
import java.util.Scanner;
import static java.lang.Math;
public class Root1
{
int a;
int b;
int c;
double root1;
public Root1(int a, int b, int c)
{
this.a=a;
this.b=b;
this.c=c;
}
public double calculateRoot1()
{
int d=calculateDeterminant();
this.root1=(-b+Math.sqrt(d))/2*a;
return root1;
}
public int calculateDeterminant()
{
int d= b*b-(4*a*c);
return d;
}
}
public class Root2
{
int a;
int b;
int c;
double root2;
public Root2(int a, int b, int c)
{
this.a=a;
this.b=b;
this.c=c;
}
public double calculateRoot2()
{
int d=calculateDeterminant();
this.root2=(-b+Math.sqrt(d))/2*a;
return root2;
}
public int calculateDeterminant()
{
int d= b*b-(4*a*c);
return d;
}
}
public class RootMain
{
Scanner input=new Scanner(System.in);
System.out.println("Enter value of a");
int a=input.nextInt();
System.out.println("Enter value of b");
int b=input.nextInt();
System.out.println("Enter value of c");
int c=input.nextInt();
public static void main(String args[])
{
Root1 r1= new Root1(a,b,c);
System.out.println(r1.calculateRoot1);
Root2 r2=new Root2(a,b,c);
System.out.println(r1.calculateRoot2);
}
}
我的尝试:
i我正在创建一个程序来查找二次方程的根但在主类中得到错误。请解决它。明天我必须在我的课堂上展示这个课程。
What I have tried:
i am creating a program of finding roots of quadratic equation but getting error in main class. please solve it. tomorrow i have to present this program in my class.
推荐答案
你不需要额外的课程,你的代码在 main之外
方法,所以这永远不会构建,更不用说运行了。请参阅 Java™教程 [ ^ ]有关创建java程序的信息。
You do not need the extra classes in there and you have code outside your main
method, so this is never going to build, let alone run. See The Java™ Tutorials[^] for information on creating a java program.
import java.util.Scanner;
import java.lang.Math;
class Root1
{
int a;
int b;
int c;
double root1;
Root1(int x, int y, int z)
{
a=x;
b=y;
c=z;
}
public double calculateRoot1()
{
int d= b*b-(4*a*c);
root1=(-b+Math.sqrt(d))/2*a;
return root1;
}
}
class Root2
{
int a;
int b;
int c;
double root2;
Root2(int x, int y, int z)
{
a=x;
b=y;
c=z;
}
public double calculateRoot2()
{
int d= b*b-(4*a*c);
root2=(-b-Math.sqrt(d))/2*a;
return root2;
}
}
public class RootMain
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
System.out.println("Enter value of a");
int a=input.nextInt();
System.out.println("Enter value of b");
int b=input.nextInt();
System.out.println("Enter value of c");
int c=input.nextInt();
Root1 r1= new Root1(a,b,c);
System.out.println("Value of Root 1 is:"r1.calculateRoot1());
Root2 r2=new Root2(a,b,c);
System.out.println("Value of Root 2 is:"r2.calculateRoot2());
}
}
这篇关于在主要课程中获得错误请解决。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文