Page 321 - Computer science 868 Class 12
P. 321

25                  }

                   26              }

                   27              System.out.println("No pythagorean triplets exist in the array");
                   28          }
                   29

                   30          public static void main()
                   31          {

                   32              Scanner sc= new Scanner(System.in);
                   33              find_PythagoreanTriplets ob = new find_PythagoreanTriplets();

                   34              System.out.println("Enter the array size");
                   35              ob.size = sc.nextInt();

                   36              ob.ar = new int[ob.size];
                   37              int i;

                   38              System.out.println("Enter array elements");
                   39              for (i = 0; i < ob.ar.length; i++)

                   40              {
                   41                  ob.ar[i] = sc.nextInt();

                   42              }
                   43              ob.printPythagoreanTriplets();

                   44          }
                   45      }


                 The output of the preceding program is as follows:
                 Enter the array size
                 5
                 Enter array elements
                 1 2 3 4 5
                 The Pythagorean triplets are 3, 4, 5


                   Program 7     Write a program to find out a given matrix is sparse matrix or not.
                                 [Sparse matrix contains zero elements above a certain threshold. This threshold is given by
                                 (n*m)/2, where n and m are the rows and columns in matrix. Hence, if a matrix contains
                                 more than nm/2 number of zeros, it is sparse matrix otherwise not.]

                   1       import java.util.*;
                   2       class Sparse_Matrix

                   3       {
                   4           int r,c;



                                                                                                                       319
                                                                                                              Arrays   319
   316   317   318   319   320   321   322   323   324   325   326