分支结构

if( )里面的表达式的结果必须是布尔型

If语句例题

判断3个坐标是否可以构建成三角形

 package javaapp3;
 import java.io.*;
 public class Javaapp3 {
 ​
     public static void main(String[] args) throws IOException {
 ​
         double x1,y1;
         double x2,y2;
         double x3,y3;
         
         BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
 ​
         String str=buf.readLine();
         x1=Double.parseDouble(str);
         str=buf.readLine();
         y1=Double.parseDouble(str);
         str=buf.readLine();
         x2=Double.parseDouble(str);
         str=buf.readLine();
         y2=Double.parseDouble(str);
         str=buf.readLine();
         x3=Double.parseDouble(str);
         str=buf.readLine();
         y3=Double.parseDouble(str);
         
         double d1,d2,d3;
         d1=Math.sqrt(Math.pow((x1-x2),2)+Math.pow((y1-y2),2));
         d2=Math.sqrt(Math.pow((x1-x3),2)+Math.pow((y1-y3),2));
         d3=Math.sqrt(Math.pow((x3-x2),2)+Math.pow((y3-y2),2));
         
         if(d1+d2>d3&&d2+d3>d1&&d1+d3>d2)
         {
             System.out.println("OK");
         }
         else
         {
             System.out.println("NO");
         }
     }
 ​
 }