Vous êtes sur la page 1sur 1

Class Hcf 1/1

1 // The Subclass
2 class Hcf extends Calculate
3 {
4 int h;
5 void findhcf()
6 {
7 accept(); // Concept of inheritance
8 int a=super.n1;
9 int b=super.n2;
10 if(a<b)
11 {
12 a=b;
13 b=super.n1;
14 }
15 int t;
16 // Calculation of hcf
17 while((a%b)!=0)
18 {
19 t=a%b;
20 a=b;
21 b=t;
22 }
23 h=b;
24 } // end of void findhcf()
25 void show()
26 {
27 System.out.println("n1"+"\t"+"n2"+"\t"+"HCF"+"\t"+"LCM");
28 super.display(); // Method overriding
29 System.out.print("\t"+h);
30 // Calculation of lcm
31 int lcm=(super.n1*super.n2)/h;
32 System.out.println("\t"+lcm);
33 System.out.println();
34 System.out.println();
35 } // end of void show()
36 public static void main(String args[])
37 {
38 Hcf obj=new Hcf();
39 // Carries out the same procedure as in class hcf
40 obj.findhcf();
41 obj.show();
42 } // end of void main()
43 } // end of class Hcf

Jul 27, 2017 5:31:33 PM

Vous aimerez peut-être aussi