java 我是新手~ 请问为什么CMD提示找不到符号呢?
publicclassQuadratic{publicstaticvoidmain(String[]args){System.out.println("1)Enterco...
public class Quadratic
{
public static void main(String[] args)
{
System.out.println("1) Enter coefficients");
System.out.println("2) Solve for given x");
System.out.println("3) Find roots");
System.out.println("4)Quit");
System.out.println("Please enter option:");
int option;
option = StdIn.readInt();
switch(option)
{
case 1:
System.out.println("Please enter a:");
int a = StdIn.readInt();
System.out.println("Please enter b:");
int b = StdIn.readInt();
System.out.println("Please enter c:");
int c = StdIn.readInt();
break;
case 2:
System.out.println("Please enter x:");
int x = StdIn.readInt();
int m = Math.pow(d,2);
int n = m + b*x + c ;
break;
case 3:
if(b*b - 4*a*c < 0)
{
System.out.println("Not real roots exist.");
}
else if (b*b - 4*a*c >=o)
{
double num = -b/(2.0*a);
double root = Math.sqrt(b*b-4*a*c)/(2.0*a);
double x1 = number - root;
double x2 = number + root;
System.out.println("Real roots of"+ x1 + "and" + x2 + "exist.");
}
break;
case 4:
System.out.println("Exit.");
}
}
}
这是一个解一元二次方程的题,我还没有写完。。。
[zy03443@unnc-cslinux ex1]$ javac Quadratic.java
Quadratic.java:27: cannot find symbol
symbol : variable d
location: class Quadratic
int m = Math.pow(d,2);
^
Quadratic.java:36: cannot find symbol
symbol : variable o
location: class Quadratic
else if (b*b - 4*a*c >=o)
^
Quadratic.java:40: cannot find symbol
symbol : variable number
location: class Quadratic
double x1 = number - root;
^
Quadratic.java:41: cannot find symbol
symbol : variable number
location: class Quadratic
double x2 = number + root;
^
Quadratic.java:41: incompatible types
found : <nulltype>
required: double
double x2 = number + root;
^
5 errors
这个是错误提示。。。
请高手来解答,万分感谢!
问题还是没有解决。。。那个d是我写错了,应该是x。。。谢谢大家。。 展开
{
public static void main(String[] args)
{
System.out.println("1) Enter coefficients");
System.out.println("2) Solve for given x");
System.out.println("3) Find roots");
System.out.println("4)Quit");
System.out.println("Please enter option:");
int option;
option = StdIn.readInt();
switch(option)
{
case 1:
System.out.println("Please enter a:");
int a = StdIn.readInt();
System.out.println("Please enter b:");
int b = StdIn.readInt();
System.out.println("Please enter c:");
int c = StdIn.readInt();
break;
case 2:
System.out.println("Please enter x:");
int x = StdIn.readInt();
int m = Math.pow(d,2);
int n = m + b*x + c ;
break;
case 3:
if(b*b - 4*a*c < 0)
{
System.out.println("Not real roots exist.");
}
else if (b*b - 4*a*c >=o)
{
double num = -b/(2.0*a);
double root = Math.sqrt(b*b-4*a*c)/(2.0*a);
double x1 = number - root;
double x2 = number + root;
System.out.println("Real roots of"+ x1 + "and" + x2 + "exist.");
}
break;
case 4:
System.out.println("Exit.");
}
}
}
这是一个解一元二次方程的题,我还没有写完。。。
[zy03443@unnc-cslinux ex1]$ javac Quadratic.java
Quadratic.java:27: cannot find symbol
symbol : variable d
location: class Quadratic
int m = Math.pow(d,2);
^
Quadratic.java:36: cannot find symbol
symbol : variable o
location: class Quadratic
else if (b*b - 4*a*c >=o)
^
Quadratic.java:40: cannot find symbol
symbol : variable number
location: class Quadratic
double x1 = number - root;
^
Quadratic.java:41: cannot find symbol
symbol : variable number
location: class Quadratic
double x2 = number + root;
^
Quadratic.java:41: incompatible types
found : <nulltype>
required: double
double x2 = number + root;
^
5 errors
这个是错误提示。。。
请高手来解答,万分感谢!
问题还是没有解决。。。那个d是我写错了,应该是x。。。谢谢大家。。 展开
6个回答
展开全部
switch(option)
{
case 1:
System.out.println("Please enter a:");
int a = StdIn.readInt();
System.out.println("Please enter b:");
int b = StdIn.readInt();
System.out.println("Please enter c:");
int c = StdIn.readInt();
break;
case 2:
System.out.println("Please enter x:");
int x = StdIn.readInt();
int m = Math.pow(d,2); //m和n是干什么用的???d也没有定义。。 。
int n = m + b*x + c ; //是不是应该打印出n??
break;
case 3:
if(b*b - 4*a*c < 0)
{
System.out.println("Not real roots exist.");
}
else if (b*b - 4*a*c >=o) // if(b*b-4*a*c>=o) 这是废话。。 而且你把0打成了o。。 建议删掉
{
double num = -b/(2.0*a);
double root = Math.sqrt(b*b-4*a*c)/(2.0*a);
double x1 = number - root; //num 是变量。。。
double x2 = number + root;
System.out.println("Real roots of"+ x1 + "and" + x2 + "exist.");
}
break;
case 4:
System.out.println("Exit.");
}
}
}
再看看这个
Quadratic.java:27: cannot find symbol
symbol : variable d
location: class Quadratic
int m = Math.pow(d,2); //这句话是告诉在27行找不到变量d
^
Quadratic.java:36: cannot find symbol
symbol : variable o
location: class Quadratic
else if (b*b - 4*a*c >=o)//36行找不到变量o 你把0打成o了
^
Quadratic.java:40: cannot find symbol
symbol : variable number
location: class Quadratic
double x1 = number - root;//40行找不到变量number
^
Quadratic.java:41: cannot find symbol
symbol : variable number
location: class Quadratic
double x2 = number + root;//41行找不到变量number
^
Quadratic.java:41: incompatible types
found : <nulltype>//这是说没有给值一个类型。。应为你错打成了number
required: double
double x2 = number + root;//这句话是说不兼容类型。在41行。
^
5 errors
看明白了多给点分哦。。
{
case 1:
System.out.println("Please enter a:");
int a = StdIn.readInt();
System.out.println("Please enter b:");
int b = StdIn.readInt();
System.out.println("Please enter c:");
int c = StdIn.readInt();
break;
case 2:
System.out.println("Please enter x:");
int x = StdIn.readInt();
int m = Math.pow(d,2); //m和n是干什么用的???d也没有定义。。 。
int n = m + b*x + c ; //是不是应该打印出n??
break;
case 3:
if(b*b - 4*a*c < 0)
{
System.out.println("Not real roots exist.");
}
else if (b*b - 4*a*c >=o) // if(b*b-4*a*c>=o) 这是废话。。 而且你把0打成了o。。 建议删掉
{
double num = -b/(2.0*a);
double root = Math.sqrt(b*b-4*a*c)/(2.0*a);
double x1 = number - root; //num 是变量。。。
double x2 = number + root;
System.out.println("Real roots of"+ x1 + "and" + x2 + "exist.");
}
break;
case 4:
System.out.println("Exit.");
}
}
}
再看看这个
Quadratic.java:27: cannot find symbol
symbol : variable d
location: class Quadratic
int m = Math.pow(d,2); //这句话是告诉在27行找不到变量d
^
Quadratic.java:36: cannot find symbol
symbol : variable o
location: class Quadratic
else if (b*b - 4*a*c >=o)//36行找不到变量o 你把0打成o了
^
Quadratic.java:40: cannot find symbol
symbol : variable number
location: class Quadratic
double x1 = number - root;//40行找不到变量number
^
Quadratic.java:41: cannot find symbol
symbol : variable number
location: class Quadratic
double x2 = number + root;//41行找不到变量number
^
Quadratic.java:41: incompatible types
found : <nulltype>//这是说没有给值一个类型。。应为你错打成了number
required: double
double x2 = number + root;//这句话是说不兼容类型。在41行。
^
5 errors
看明白了多给点分哦。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
变量都没定义就使用了,当然就报错了。使用变量之前一定要先定义,要初始化,有时候定义了变量还报错,要看下它的作用域。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
int m = Math.pow(d,2); 你这个d变量没有定义
你得先double d = 0.0;
你得先double d = 0.0;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把所有关于初始化的内容全拿出switch吧,拿出去初始化了再在里面用
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询