answersLogoWhite

0


Best Answer

//Perhaps this is what you want.

//@author Rosencrantz

import java.util.Scanner;

class TriangleFun

{

public static void main(String[] args)

{

Scanner scan = new Scanner(System.in);

boolean done = false;

while(true)

{

System.out.print("Calculate AREA or PERIMETER? Type DONE to quit.");

String input = scan.nextLine().trim();

if(input.equalsIgnoreCase("DONE"))

break;

if(input.equalsIgnoreCase("AREA"))

{

System.out.print("Enter the base length: ");

double base = scan.nextDouble();

System.out.print("Enter the height: ");

double height = scan.nextDouble();

System.out.println("Area is: " + (1/2.0) * base * height);

}

else

{

System.out.print("Enter length of side 1: ");

double length1 = scan.nextDouble();

System.out.print("Enter length of side 2: ");

double length2 = scan.nextDouble();

System.out.print("Enter length of side 3: ");

double length3 = scan.nextDouble();

System.out.println("Perimeter is: " + (length1 + length2 + length3));

}

scan.nextLine();

}

}

}

//A better edited version is in the links

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Using function create a program that will ask the user if he wants to compute the perimeter or the area of the triangle in your main program If the perimeter is wanted ask the measures of the three si?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Write a java that computes the value of 2?

Compute means to calculate. What do you want to "compute", if you already know it is 2? If you want to show the value:System.out.println("Your number is " + 2);Compute means to calculate. What do you want to "compute", if you already know it is 2? If you want to show the value:System.out.println("Your number is " + 2);Compute means to calculate. What do you want to "compute", if you already know it is 2? If you want to show the value:System.out.println("Your number is " + 2);Compute means to calculate. What do you want to "compute", if you already know it is 2? If you want to show the value:System.out.println("Your number is " + 2);


How do you compute the integral of a function using midpoint rule in C programming?

Please refer to Wikipedia where there is a full C example to do specifically this. I imagine whoever had the homework assignment before you posted their answer there.


Write algorithm compute sum of square of N numbers?

1. Design an algorithm to compute sum of the squares of n numbers?


How do you write a program in c to compute the power of a number without using the mathh library?

There is a function which can do it for you. You have to include math.h in headers. And then use the function pow(x, y) which returns a value of type double (x and y are double too).pow(x, y) = x to the power of y.


What is the function that compute the CPU utilization in c plus plus language?

There is no such function in C++ as the implementation is hardware-dependant and would require a low-level operating system API call. C++ is designed to be as generic as possible, thus there are no built-in functions to cater for this. See related links below for an article which describes how such information can be obtained.

Related questions

What does it mean when a question asks you to compute the perimeter?

Compute = calculate; perimeter = measurement of the outside edge.


How do you calculate perimeter of a triangle?

-- Measure or calculate the length of one side. -- Measure or calculate the length of another side. -- Measure or calculate the length of the only remaining side. -- Add the three numbers. The sum is the perimeter of the triangle. ----------------------------------- The perimeter is the sum of all three sides. Sometimes it is unnecessary to compute each side length; all we care about is the sum.


How do you compute a half triangle?

math


How do you compute the perimeter of a rectangle?

add the lengths of all the sides


Flowchart to find area of area and perimeter of a square?

creat a flowchart that will compute for the area and perimeter of a square?


Give an example to compute a right triangle?

an example of solving a right triangle


How do you compute the probability distribution of a function of two Poisson random variables?

we compute it by using their differences


What does it mean when it says compute both the perimeter and area?

Usually that means figure out the area and perimeter. Remember the perimeter is adding all sides like putting up and fence. And the area is x (multiplying) the 2 sides


How do you compute a perimeter of trapezoid?

There is no simple formula: you just need to add together the lengths of each of the 4 sides.


Write a pascal program that compute an area of a triangle?

{A program to compute the area of a triangle} {by Ogboin W. Meshach} Var; b,h:real; BEGIN Writeln('Triangle'); Write('Base: '); Readln(base); Write('Height: '); Readln(height); area:=0.5*base*height; Writeln('Area: ', area :0:2); End.


What are the advantages of sigmoidal function in neural network?

its derivative is easy to compute


How do you compute norm on matlab?

using the function norm(A,x) where A is the matrix/vector that you have to compute the norm for and x can be 1,2,inf, or 'fro' to compute the 1-norm, 2-norm, infinite-norm and frobenius norm respectively.