In: Computer Science
(JAVA) Write an application that reads three nonzero values entered by the user and determines and prints whether they could represent the sides of a triangle. Enter three sizes, separated by spaces(decimals values are acceptable): 4.5·5.5·3.5 A triangle could measure 4.50, 5.50, by 3.50.
import java.util.Scanner; public class TriangleCheck { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); double a, b, c; System.out.println("Enter three sizes, separated by spaces(decimals values are acceptable): "); a = scanner.nextDouble(); b = scanner.nextDouble(); c = scanner.nextDouble(); if (a + b <= c || a + c <= b || b + c <= a){ System.out.printf("A triangle could NOT measure %.2f, %.2f, by %.2f.",a,b,c); } else{ System.out.printf("A triangle could measure %.2f, %.2f, by %.2f.",a,b,c); } System.out.println(); } }