English

Define a class Triplet with the following specifications: Class name: TripletData members: int a, int b, int cMember methods:void getdata(): to accept three numbersvoid findprint(): - Computer Applications

Advertisements
Advertisements

Question

Define a class Triplet with the following specifications: 

Class name: Triplet
Data members: int a, int b, int c
Member methods:
void getdata(): to accept three numbers
void findprint(): to check and display whether the numbers are Pythagorean Triplets or not.

Code Writing

Solution

import java.util.*;
class Triplet
{int a, b, c;

void getdata()
{Scanner in = new Scanner(System.in);
System.out.println("Enter the length of the hypotenuse");
c = in.nextInt();
System.out.println("Enter the other two sides of the triangle");
a = in.nextInt();
b = in.nextInt();
}

void findprint()
{if ((a * a) + (b * b) == (c * c))
System.out.println("YES! It is a Pythagorean Triplet");
else
System.out.println("NO. It is not a Pythagorean Triplet");
}
public static void main(String args[])
{Triplet t = new Triplet();
t.getdata();
t.findprint();
}
}
shaalaa.com
  Is there an error in this question or solution?
Chapter 6: Class as the Basis of all Computation (Objects and Classes) - EXERCISES [Page 384]

APPEARS IN

Avichal Computer Applications [English] Class 10 ICSE
Chapter 6 Class as the Basis of all Computation (Objects and Classes)
EXERCISES | Q VI. 2. | Page 384
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×