Computer Applications
Write a program in Java to accept three numbers and check whether they are Pythagorean Triplet or not. The program must display the message accordingly. [Hint: h2=p2+b2]
Java
Java Conditional Stmts
102 Likes
Answer
import java.util.Scanner;
public class KboatPythagoreanTriplet
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter 1st number: ");
int a = in.nextInt();
System.out.print("Enter 2nd number: ");
int b = in.nextInt();
System.out.print("Enter 3rd number: ");
int c = in.nextInt();
if (a * a + b * b == c * c ||
a * a + c * c == b * b ||
b * b + c * c == a * a)
System.out.println("Pythagorean Triplets");
else
System.out.println("Not Pythagorean Triplets");
}
}
Output
Answered By
40 Likes
Related Questions
Star mall is offering discount on various types of products purchased by its customers. Following table shows different type of products and their respective code along with the discount offered. Based on the code entered, the mall is calculating the total amount after deducting the availed discount. Create a program to calculate total amount to be paid by the customer.
Item Item Code Discount Laptop L 5% LCD D 7% XBox X 10% Printer P 11% Write a menu driven program to accept a number from the user and check whether it is a Buzz number or an Automorphic number.
i. Automorphic number is a number, whose square's last digit(s) are equal to that number. For example, 25 is an automorphic number, as its square is 625 and 25 is present as the last two digits.
ii. Buzz number is a number, that ends with 7 or is divisible by 7.Write a Java program in which you input students name, class, roll number, and marks in 5 subjects. Find out the total marks, percentage, and grade according to the following table.
Percentage Grade >= 90 A+ >= 80 and < 90 A >= 70 and < 80 B+ >= 60 and < 70 B >= 50 and < 60 C >= 40 and < 50 D < 40 E Using switch case, write a program to convert temperature from Fahrenheit to Celsius and Celsius to Fahrenheit.
Fahrenheit to Celsius formula: (32°F - 32) x 5/9
Celsius to Fahrenheit formula: (0°C x 9/5) + 32