- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果输入正确,我想在运行时调用区域实例变量以在Setter方法中显示其值。我正在使用 TriangleTester 来测试 Triangle 类。我只想根据所需的输出计算三角形的面积和周长
Triangle.java
import java.util.Scanner;
class Triangle
{
private int a,b,c; //sides of the triangle
private double s,area; //and 's' for the Heron's Formula
private int peri;
String type=new String();
Triangle()
{
System.out.println("*****A Java Application To Determine Triangle and Comupute*****");
setter();
}
public void inputAndDetermine()
{
if(((a+b)>c)&&((a+c)>b)&&((b+c)>a))
{
determineType();
calculatePerimeter();
calculateArea();
displayResult();
}
else
{
System.out.println("The input doesn't describe a triangle");
}
}
public void determineType()
{
if((a==b)&&(a==c))
{
type="Equilateral triangle";
}
else if((a==b)||(b==c)||(a==c))
{
type="Isoceles triangle";
}
else
{
type="Scalene triangle";
}
}
public void calculatePerimeter()
{
peri=a+b+c;
}
public strictfp void calculateArea()
{
s=(a+b+c)/2;
area=(Math.sqrt((s*(s-a)*(s-b)*(s-c))));
}
public void displayResult()
{
System.out.println("\t Summary of Computing Triangle Perimeters & Areas \t");
System.out.println("----------------------------------------------------------");
System.out.println("\t Sides(a,b,c) \t Perimeter \t Area \t Type \t");
System.out.println("----------------------------------------------------------");
System.out.println("\t " + a + " " + b + " " + c + "\t " + peri + "\t " + area + "\t" + type );
System.out.println("");
System.out.println("");
System.out.println("Bar Chart Of Number of Triangle Constructed");
}
public void setter()
{
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter the length of 1st side of Triangle 1 : ");
this.a=keyboard.nextInt();
System.out.print("Enter the length of 1st side of Triangle 1 : ");
this.b=keyboard.nextInt();
System.out.print("Enter the length of 1st side of Triangle 1 : ");
this.c=keyboard.nextInt();
System.out.println("The Triangle perimeter and area are :");
System.out.println("\t \t" + peri + " unit, " + area + " units. " + type );
System.out.println("-----------------------------------------------------------");
}
}
TriangleTester.java
class TriangleTester
{
public static void main(String [] ar)
{
Triangle tri = new Triangle();
tri.inputAndDetermine();
}
}
这是我得到的输出
最佳答案
将setter方法代码更改为
...
this.c=keyboard.nextInt();
// add these two lines
calculatePerimeter();
calculateArea();
System.out.println("The Triangle perimeter and area are :");
System.out.println("\t \t" + peri + " unit, " + area + " units. " + type );
System.out.println("-----------------------------------------------------------");
但这似乎毫无意义。
关于java - 实例变量没有在方法中被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45666117/
我正在使用 Gunicorn 为 Django 应用程序提供服务,它工作正常,直到我将其超时时间从 30 秒更改为 900000 秒,我不得不这样做,因为我有一个用例需要上传和处理一个巨大的文件(过程
我有一个带有非常基本的管道的Jenkinsfile,它可以旋转docker容器: pipeline { agent { dockerfile { args '-u root' } } stag
在学习 MEAN 堆栈的过程中,我遇到了一个问题。每当我尝试使用 Passport 验证方法时,它都不会返回任何响应。我总是收到“localhost没有发送任何数据。ERR_EMPTY_RESPONS
在当今的大多数企业堆栈中,数据库是我们存储所有秘密的地方。它是安全屋,是待命室,也是用于存储可能非常私密或极具价值的物品的集散地。对于依赖它的数据库管理员、程序员和DevOps团队来说,保护它免受所
是否可以创建像图片上那样的边框?只需使用 css 边框属性。最终结果将是没 Angular 盒子。我不想添加额外的 html 元素。我只想为每个 li 元素添加 css 边框信息。 假设这是一个 ul
我是一名优秀的程序员,十分优秀!