zoukankan      html  css  js  c++  java
  • UT源码+037

    (1)设计三角形问题的程序

          输入三个整数a、b、c,分别作为三角形的三条边,现通过程序判断由三条边构成的三角形的类型为等边三角形、等腰三角形、一般三角形(特殊的还有直角三角形),以及不构成三角形。(等腰直角三角形,判断为等腰三角形)

         现在要求输入三个整数a、b、c,必须满足以下条件:

         条件1   1≤a≤100          条件4   a<b+ c

         条件2   1≤b≤100          条件5   b<a+ c            

         条件3   1≤c≤100          条件6   c<a+ b 

      String triangle(int a,int b,int c)    返回字符型

     程序要求:

    1)先显示:“请输入三角形的三条边:”

    2)只要有不满足条件1,2,3之一,就返回“边的值不在范围内!”

    3)只要有不满足4,5,6之一,就返回“不构成三角形”

    4)根据边的情况分别返回:“等边三角形”“等腰三角形”“直角三角形”“一般三角形”

     1 public class Sort{
     2     static String t1="边的值不在范围内";
     3     static String t2="不构成三角形";
     4     static String t3="等边三角形";
     5     static String t4="等腰三角形";
     6     static String t5="直角三角形";
     7     static String t6="一般三角形";
     8     public static String triangle(int a,int b,int c){    
     9         if(a<1 || a>100 ||b<1 || b>100|| c<1|| c>100)
    10         {
    11             return t1;
    12         }
    13         else if(a>=b+c ||b>=a+c||c>=a+b)
    14         {
    15             return t2;
    16         }
    17         else if(a==b &&b==c &&c==a){
    18             return t3;
    19         }
    20         else if(a==b ||b==c ||c==a){
    21             return t4;
    22         }
    23         else if(a*a+b*b==c*c ||b*b+c*c==a*a ||c*c+a*a==b*b){
    24             return t5;
    25         
    26         }
    27         else {
    28             return t6;
    29         }
    30     }
    31 }
     1 package TSort;
     2 
     3 import java.util.Scanner;
     4 
     5 public class Menu {
     6     private static Scanner in = new Scanner(System.in);
     7     public Menu() throws Exception
     8     {
     9         while(true){
    10             this.show();
    11         }
    12     }
    13     public void show() throws Exception{
    14         
    15         System.out.println("======三角形种类=====");
    16         System.out.println("[1] 进行三角形类型判断");
    17         System.out.println("[e] 退出。");
    18         while (in.hasNext()) {
    19         String i = in.nextLine();
    20         switch(i){
    21             case "1":{
    22                 System.out.println("请输入三角形的三条边:");
    23                 Scanner scana=new Scanner(System.in);
    24                 int a = scana.nextInt();
    25                 Scanner scanb=new Scanner(System.in);
    26                 int b = scanb.nextInt();
    27                 Scanner scanc=new Scanner(System.in);
    28                 int c = scanc.nextInt();
    29                 Sort.triangle(a,b,c);
    30                 System.out.println(Sort.triangle(a, b, c));
    31                 System.out.println("=====================");
    32                 System.out.println("[1] 进行三角形类型判断");
    33                 System.out.println("[e] 退出。");
    34                 break ;
    35             }
    36             
    37             case "e":{
    38                 System.exit(1) ;        // 系统退出
    39                 break ;
    40             }
    41             default:{
    42                 System.out.println("请选择正确的操作!") ;
    43             }
    44         }
    45     }
    46     }
    47 }
    1 package TSort;
    2 
    3 public class Client {
    4     public static void main(String args[]) throws Exception{
    5         new Menu();
    6     }
    7 }
  • 相关阅读:
    Jmeter运行badboy录制的脚本
    Bugfree安装与使用
    JMeter录制脚本
    第六天-linux系统优化初步讲解
    第五天-linux基础命令
    第四天-secureCRT-ssh客户端使用详解
    第三天-linux版本选择及安装
    第二天-计算机硬件基本知识和linux发展简史
    第一天-学习linux运维
    ubuntu15.04 无线上网问题
  • 原文地址:https://www.cnblogs.com/WuYeqian/p/6531246.html
Copyright © 2011-2022 走看看