java初学者问题!谢谢!答得好追加分数!

来源:百度知道 编辑:UC知道 时间:2024/09/21 17:39:26
从键盘输入a、b、c三个整数,判断是否能构成三角形的三条边,首先判断是否三个数都大于零,然后判断是否人以两个数之和大于第三个数。
import java.io.*;
public class sanjiaoxing
{

public static void main(String args[])throws IOException
{
int a;
int b;
int c;
String str;
BufferedReader buf;
buf=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Input a is:");
str=buf.readLine();
a=Integer.parseInt(str);
System.out.print("Input b is:");
str=buf.readLine();
b=Integer.parseInt(str);
System.out.print("Input c is:");
str=buf.readLine();
c=Integer.parseInt(str);
if(a>0)&&(b>0)&&(c>0) //第22行
{if(a+b>c)&&(a+c>b)&&(b+c>a)//第23行
System.out.println("YES");//第24行
else
System.out.println("NO");
}
else //第28行
System.out.println("NO");
}
}

很简单,if后面的表达式要用()
if((a>0)&&(b>0)&&(c>0)) //第22行
{if((a+b>c)&&(a+c>b)&&(b+c>a))//第23行

if((a>0)&&(b>0)&&(c>0)) //第22行
{
if(((a+b)>c)&&((a+c)>b)&&((b+c)>a))//第23行
System.out.println("YES");//第24行
else
System.out.println("NO");
}

楼上说的对

就22 23行有错

改了之后就好了

楼上说的对,