用Java写,

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/28 13:12:29
用Java写,
xTN1~+Hț'I"U "U =;`z{Z!$N}.A߫M8xT\V^{~>쎪_Gp~>GZA5=0EUzddݽ=Fc^ n!g1-e-\ǁBl Eƛh_4sVP4'ӯ "ddA_U|$HͼŽ'Ѯ.ؘZ~kֲΖ,E8p˧VLs3e5>P¸VuJ BZt萷kN\֌IUΊtY[hxCEouXK^E;\N*~!ff@v :RgQK\uՎl]M7sf%i<ĚzCZ=[؜m"^وh*pѢ[i

用Java写,
用Java写,

用Java写,
import java.io.*;
  import java.util.*;
  import java.lang.Math.*;
  import java.text.*;
  import java.math.RoundingMode;
  class Main
  {
  public static void main(String[] args)
  {
  int a,b,c;
  double result;
  int num = 1;
  DecimalFormat f = new DecimalFormat("#.000");
  f.setRoundingMode(RoundingMode.HALF_UP);
  Scanner cin = new Scanner(System.in);
  while(true)
  {
  a = cin.nextInt();
  b = cin.nextInt();
  c = cin.nextInt();
  if(a==0&&b==0&&c==0) break;
  System.out.println("Triangle #" + num);
  num++;
  if(a==-1)
  {
  if(b>=c)
  {
  System.out.println("Impossible.");
  }
  else
  {
  result = Math.sqrt(c*c-b*b);
  System.out.println("a = " + f.format(result));
  }
  }
  else if(b==-1)
  {
  if(a>=c)
  {
  System.out.println("Impossible.");
  }
  else
  {
  result = Math.sqrt(c*c-a*a);
  System.out.println("b = " + f.format(result));
  }
  }
  else
  {
  result = Math.sqrt(a*a+b*b);
  System.out.println("c = " + f.format(result));
  }
  System.out.println();
  }
  }
  }