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 }
  • 相关阅读:
    Maximum Depth of Binary Tree
    Single Number
    Merge Two Sorted Lists
    Remove Nth Node From End of List
    Remove Element
    Remove Duplicates from Sorted List
    Add Two Numbers
    编译视频直播点播平台EasyDSS数据排序使用Go 语言 slice 类型排序的实现介绍
    RTMP协议视频直播点播平台EasyDSS在Linux系统中以服务启动报错can’t evaluate field RootPath in type*struct排查
    【解决方案】5G时代RTMP推流服务器/互联网直播点播平台EasyDSS实现360°全景摄像机VR直播
  • 原文地址:https://www.cnblogs.com/WuYeqian/p/6531246.html
Copyright © 2011-2022 走看看