Write a class program with the following specifications:
Class Name — Triplet
Data Members — int a, b, c
Member Methods:
void getdata() — to accept three numbers
void findprint() — to check and display whether the numbers are Pythagorean Triplets or
not.
Answers
Answer:
import java.util.Scanner; public class Triplet { private int a; private int b; private int c; public void getdata() { Scanner in = new Scanner(System.in); System.out.print("Enter a: "); a = in.nextInt(); System.out.print("Enter b: "); b = in.nextInt(); System.out.print("Enter c: "); c = in.nextInt(); } public void findprint() { if ((Math.pow(a, 2) + Math.pow(b, 2)) == Math.pow(c, 2) || (Math.pow(b, 2) + Math.pow(c, 2)) == Math.pow(a, 2) || (Math.pow(a, 2) + Math.pow(c, 2)) == Math.pow(b, 2)) System.out.print("Numbers are Pythagorean Triplets"); else System.out.print("Numbers are not Pythagorean Triplets"); } public static void main(String args[]) { Triplet obj = new Triplet(); obj.getdata(); obj.findprint(); }
Explanation:
this is your answer