publicstaticvoidmain(String[] args){ System.out.println("开始"); // 定义两个变量 int a = 10; int b = 20; //变量使用if判断 if (a == b){ System.out.println("a等于b"); } int c = 10; if(a == c){ System.out.println("a等于c"); } System.out.println("结束"); }
publicstaticvoidmain(String[] args){ int a = 10; int b = 20; //定义变量,保存a和b的较大值 int c; if(a > b) { c = a; } else { c = b; } //可以上述功能改写为三元运算符形式 c = a > b ? a:b; }
publicclasstriangle{ publicstaticvoidmain(String[] args){ int a = 1; int b = 2; int c = 2; if(a>0&&b>0&&c>0){ if((a+b)>c&(a+c)>b&(c+b)>a){ if (a == b && b== c && a==c){ System.out.println("是等边三角形"); }elseif (a == a | b == c | b == c){ System.out.println("是等腰三角形"); }else { System.out.println("是三角形"); } }else{ System.out.println("不是三角形"); } }else{ System.out.println("边长不能为零"); }