我在指南的帮助下完成了三角形面积计算的基本代码。然后我添加了一些代码来让它更有趣,但我希望它在你得到结果后重置。我希望程序在使用有效值完成先前的计算后重置为“输入三角形的底数:”。如果它在 (x) 时间后重置会很好。
只是我希望它在任务完成后按下虚拟计算器中的 C 按钮。
代码:
import java.util.Scanner;
import java.util.Timer;
import java.util.TimerTask;
public class TriangleArea {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args)
{
//declare variables to hold the base and height
double base;
double height;
//Variables created. move on
System.out.print("Enter the triangle's base: ");
base = sc.nextDouble();
//Base has been declared and filled in
System.out.print("Enter the triangle's height: ");
height = sc.nextDouble();
//Both variables are filled in
double preArea = base * height;
//now we need to divide by 2
double Area = preArea / 2;
//There we go. All variables are done, area has been calculated.
System.out.println("The area of your triangle is: " + Area);
int Outcome;
if (Area <= 100) {
System.out.println("Triangle's area is small");
}
if (Area <= 300) {
System.out.println("Triangles size is medium");
}
if (Area >= 300) {
System.out.println("Triangle's area is big");
}
else {
}
}
}
莫回无
aluckdog
相关分类