1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Nadya [2.5K]
2 years ago
7

Write a Java program that prompts the user to enter integer values for the sides of a triangle and then displays the values and

the type of triangle they represent. If the user enters values that do not make a valid triangle, or if any values are not greater than zero, your program should display the values entered as well the following error message: The values entered do not make a valid triangle.
Computers and Technology
1 answer:
satela [25.4K]2 years ago
7 0

Answer:

import java.util.Scanner;

public class triangle {

       public static void main (String [] args) {

           int sideOne, sideTwo, sideThree;

           Scanner in = new Scanner (System.in);

           System.out.println("Enter the first side of the triangle");

           sideOne = in.nextInt();

           System.out.println("Enter the secon side of the triangle");

           sideTwo = in.nextInt();

           System.out.println("Enter the third side of the triangle");

           sideThree = in.nextInt();

           if ( sideOne<=0||sideTwo<=0|| sideThree<=0){

               System.out.println(" The Values enter are "+sideOne+ "," +sideThree+ ","+sideThree+ " These values don't make a valid triangle");

           }

           else if ((sideOne + sideTwo> sideThree) || (sideOne+sideThree > sideTwo) || (sideThree+sideTwo > sideOne))

           {

               System.out.println ("The triangle is Valid");

           }

           else {

               System.out.println(" The Values enter are "+sideOne+ "," +sideTwo+ ","+sideThree+ " These values don't make a valid triangle");

           }

       }

Explanation:

for a Triangle to be Valid one of the three sides of the triangle must greater than the other two sides.  The code above enforces this condition using an if statement in combination with the Or Operator

The following conditions where enforced

side one, side two and side three != 0

Side One + Side Three > Side Two

Side Three + Side Two> Side One

Side Two + Side One > Side Three

You might be interested in
Can somebody explain me what this code does in a few or one sentence?#include #include using namespace std;int main () { const i
goblinko [34]

Answer:

The program declares and array of 8 elements and swap the position of the 1st element with the 8th; the 2nd with the 7th, the 3rd with the 6th and the 4th with the 5th element

Explanation:

First, I'll arrange the code line by line, then I'll start my explanation from the variable declaration at line 4

#include

using namespace std;

int main () {

const int NUM_ELEMENTS = 8;

vector numbers(NUM_ELEMENTS);

int i = 0;

int tmpValue = 0;

cout << "Enter " << NUM_ELEMENTS << " integer values..." << endl;

for (i = 0; i < NUM_ELEMENTS; ++i)

{

cout << "Enter Value#" << i+1 << ": "; cin >> numbers.at(i);

}

for (i = 0; i < (NUM_ELEMENTS /2); ++i)

{

tmpValue = numbers.at(i); numbers.at(i) = numbers.at(NUM_ELEMENTS - 1 - i);

numbers.at(NUM_ELEMENTS - 1 - i) = tmpValue;

}

system ("pause");

return 0;

}

Line 4: This line declares an instant constant variable NUM_ELEMENTS with a constant value of 8. Meaning that the value cannot be changed during program execution.

Line 5: This line declares a vector array that can change in size. Here, it was declared with size 8.

Line 6 & 7: These lines declares integers variables i and tmpValue with an initialised value of 0, each.

Line 8: This line prints the following string; Enter 8 integer values...

Line 9 to 12: These lines represent an iteration which starts from 0 to 7.

Side Note: When an array is being declared, the index starts from 0 and ends at 1 less that the array size.

So, during this iteration, it accepts inputs into the array from index 0 to 7 i.e. from the first element till the last

Line 13 to 17: This is also an iterative statement. But what this iteration does is that, it swaps elements of the array (as stated in the answer section)

The iteration starts from 0 and ends at a value less than NUM_ELEMENTS/2

Note that NUM_ELEMENTS = 2

So,we can conclude that the iteration starts from 0 till a value less that 8/2

Iteration: 0 till a value less that 4

So, that's 0 to 3 (the iteration is done on array element at index 0,1,2 and 3).

When iteration is at 0, the following is done

tmpValue = number at index 0 i.e. a temporary value is used to store the number at index 0 of the array

Number at 0 = number at (8-1-0)

i.e. number at 0 = number at (7)

Number at 7 is then equal to tmpValue

Swap Completed.

The same is done for index 1,2 and 3.

4 0
3 years ago
true or false manual handling of materials accounts for the primary source of energy in the workplace
Rus_ich [418]
True, hope this helps
6 0
2 years ago
Read 2 more answers
Join my discord server! CODE IS (CebjBXN)​
11Alexandr11 [23.1K]

Answer:

sure

Explanation:

7 0
2 years ago
Read 2 more answers
Tinh T = a1*a2*a3*...an<br><br> Giúp em với
Studentka2010 [4]

Answer:

??????

Explanation:

??????? okay okay

3 0
2 years ago
I need more friends plz talk with me
Bad White [126]

Answer:

hello hru??

Explanation:

<h2><em><u>PLEASE</u></em><em><u> MARK</u></em><em><u> ME</u></em><em><u> BRAINLIEST</u></em><em><u> AND</u></em><em><u> FOLLOW</u></em><em><u> ME</u></em><em><u> LOTS</u></em><em><u> OF</u></em><em><u> LOVE</u></em><em><u> FROM</u></em><em><u> MY</u></em><em><u> HEART</u></em><em><u> AND</u></em><em><u> SOUL</u></em><em><u> DARLING</u></em><em><u> TEJASWINI</u></em><em><u> SINHA</u></em><em><u> HERE</u></em><em><u> ❤️</u></em></h2>
6 0
2 years ago
Read 2 more answers
Other questions:
  • Explain the role of the domain name system
    15·1 answer
  • A program requires that you change your screen size from 1024 X 728 to 800 X 600. In which of the following locations should you
    7·2 answers
  • To use a stored address, C provides us with an indirection operator, ____.
    6·1 answer
  • Ile 1 cm<br> ?<br> 50 m<br> The an
    5·2 answers
  • If we collect data on the number of wins each team in the NFL had during the 2011-12 season, we have _____________ data.
    10·1 answer
  • Your company is a small start-up that has leased office space in a building shared by other businesses. All businesses share a c
    6·1 answer
  • in a stop-and-wait arq system, the bandwidth of the line is 1 mbps, and 1 bit takes 10 ms to make a round trip. if the system da
    12·1 answer
  • Write a program to find the principle amount​
    10·1 answer
  • HW2.24. Statement: Area of a Triangle The area of a triangle can be computed by knowing the base and height of the triangle usin
    11·1 answer
  • In a selection, the else clause executes ______________. a. always b. when the tested condition is false c. when the tested cond
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!