「java编写三角形」java编写三角形图案如何居中

博主:adminadmin 2023-03-22 19:55:10 581

今天给各位分享java编写三角形的知识,其中也会对java编写三角形图案如何居中进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

JAVA设计一个三角形类Trival,其中的属性包括三角形的底di,三角形的高gao?

public class Trival

public void setDi(float di) {

this.di = di;

public void setGao(float gao) {

this.gao = gao;

System.out.println("底 = "+di+",高 = "+gao+ "的三角形的面积 = " + di*gao/2);

public static void main(String[] arg)

Trival trival = new Trival();

trival.setDi(3);

trival.setGao(5);

trival.findArea();

}

当编辑并运行一个Java程序时

需要同时涉及到这四种方面。使用文字编辑软件(例如记事本、写字板、UltraEdit等)或集成开发环境(Eclipse、MyEclipse等)在Java源文件中定义不同的类,通过调用类(这些类实现了Java API)中的方法来访问资源系统;

把源文件编译生成一种二进制中间码,存储在class文件中,然后再通过运行与操作系统平台环境相对应的Java虚拟机来运行class文件,执行编译产生的字节码,调用class文件中实现的方法来满足程序的Java API调用。

以上内容参考:百度百科-Java

java 编程 三角形

//java编程:输入三角形的三边,并输出,同时判断这三边能否构成三角形, 

public class Triangle2 

   private double sideA,sideB,sideC;//外部不能改变这些变量的值,只能在类中使用方法来修改和获得这些变量的值  

       public void setSide(double sideA,double sideB,double sideC)

       {   

        this.sideA=sideA;//成员变量被局部变量隐藏,需要使用this关键字使用被隐藏的成员变量  

            this.sideB=sideB;   

        this.sideC=sideC; 

   }    

   public double getSideA()  

   {   

      return sideA; 

   }   

   public double getSideB()  

   {   

      return sideB;  

   }    

   public double getSideC()  

   {   

      return sideC;  

   }   

   public boolean isOrNotTrangle()//判断三边能否构成三角形  

       {   

          if(sideA+sideBsideCsideA+sideCsideBsideB+sideCsideA)   

   {    

      return true; 

   }   

   else   

   {    

     return false;  

   }

    }  

 } 

class Example1

 { 

    public static void main(String args[])

    { 

     double sideA,sideB,sideC; 

     Triangle2 triangle=new Triangle2();   

     triangle.setSide(7.2,8.3,9.6);  

     sideA=triangle.getSideA();  

     sideB=triangle.getSideB(); 

     sideC=triangle.getSideC();  

     System.out.println("输入的三角形的三边为:"+sideA+" "+sideB+" "+sideC);

         boolean isOrNotTrangle=triangle.isOrNotTrangle();

         if(isOrNotTrangle==true)  

           {   

          System.out.println("这三边可以构成三角形");   

       }   

     else 

       {  

          System.out.println("这三边不可以构成三角形");

           } 

       }

   }

java编写三角形类Triangle

public class Triangle {

    private Integer bottom;

    private Integer height;

    public Triangle(Integer bottom, Integer height) {

        this.bottom = bottom;

        this.height = height;

    }

    public Integer getBottom() {

        return bottom;

    }

    public void setBottom(Integer bottom) {

        this.bottom = bottom;

    }

    public Integer area() {

        return this.bottom * this.height / 2;

    }

}

public class TriangleTest {

    public static void main(String[] args) {

        Triangle triangle = new Triangle(10, 5);

        System.out.println(triangle.area());

    }

}

如果觉得可以可以关注简书/微信公众号:早晚程序员

Java语言杨辉三角

打印杨辉三角代码如下:

public class woo {

public static void triangle(int n) {

int[][] array = new int[n][n];//三角形数组

for(int i=0;iarray.length;i++){

for(int j=0;j=i;j++){

if(j==0||j==i){

array[i][j]=1;

}else{

array[i][j] = array[i-1][j-1]+array[i-1][j];

}

System.out.print(array[i][j]+"\t");

}

System.out.println();

}

}

public static void main(String args[]) {

triangle(9);

}

}

扩展资料:

杨辉三角起源于中国,在欧洲这个表叫做帕斯卡三角形。帕斯卡(1623----1662)是在1654年发现这一规律的,比杨辉要迟393年。它把二项式系数图形化,把组合数内在的一些代数性质直观地从图形中体现出来,是一种离散型的数与形的优美结合。

杨辉三角具有以下性质:

1、最外层的数字始终是1;

2、第二层是自然数列;

3、第三层是三角数列;

4、角数列相邻数字相加可得方数数列。

用java编写程序求三角形的面积

构成三角形的条件,要根据任意两边和要大于第三边。代码如下:

import java.util.Scanner;

public class woo {

public static void main(String args[]) {

Scanner scan =new Scanner(System.in);

System.out.println("输入三角形的三边");

int a = scan.nextByte();

int b = scan.nextByte();

int c = scan.nextByte();

float s =(a+b+c)/2f;

float S = (float) Math.sqrt(s*(s-a)*(s-b)*(s-c));

if (a+bc b+ca a+cb){

System.out.println(S);

}

else{

System.out.println("不构成三角形");

}

}

}

扩展资料:

三角形是由同一平面内不在同一直线上的三条线段‘首尾’顺次连接所组成的封闭图形,在数学、建筑学有应用。

常见的三角形按边分有普通三角形(三条边都不相等),等腰三角(腰与底不等的等腰三角形、腰与底相等的等腰三角形即等边三角形);按角分有直角三角形、锐角三角形、钝角三角形等,其中锐角三角形和钝角三角形统称斜三角形。

三角形在平面上三角形的内角和等于180°,在平面上三角形的外角和等于360° , 在平面上三角形的外角等于与其不相邻的两个内角之和。

参考资料:

三角形面积公式——百度百科

用Java程序编写一个三角形的类,三条边为三个属性求三角形的面积和周长,并设计构造方法

import java.util.Scanner;

public class TestDeadLock{

    public static void main(String[] args){

        double a, b, c;  //三角形三条边

        Scanner sc = new Scanner(System.in);

        System.out.println("请输入三角形的三条边长(回车键输入下一位):");

        a = sc.nextDouble();

        b = sc.nextDouble();

        c = sc.nextDouble();

        Triangle angle = new Triangle(a, b, c);

        if(angle.isTriangle()){

            System.out.println("三角形的周长是:" + angle.pereTriangle());

            System.out.println("三角形的面积是:" + angle.areaTriangle());

        }else

            System.out.println("这三个边长不能组成三角形:" + a + "  " + b + "  " + c);

    }   

}

class Triangle{

    private double a, b, c;

    public Triangle(double a, double b, double c){

        this.a = a; 

        this.b = b;

        this.c = c;

    }

    

    public boolean isTriangle(){

        if( a + b  c  a + c  b   b + c  a){ return true;}

        else

            return false;

    }

    

    public double pereTriangle(){

        return a + b + c;

    }

    

    public double areaTriangle(){

        double area = 0.0, temp = 0.0;

        temp = 0.5 * (a + b + c);

        area =  Math.sqrt(temp * (temp -a) * (temp -b) * (temp -c));

        return area;

    }

    

}

关于java编写三角形和java编写三角形图案如何居中的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。