Page 566 - ComputerScience_Class_11
P. 566

28               {
                29                   for (int i = 2; i <= count / 2; i++)

                30                   {
                31                       if (count % i == 0)

                32                       {
                33                           isPrime = false;

                34                           break;
                35                       }
                36                   }

                37               }

                38
                39               if (isPrime && count >= 2)
                40               {

                41                System.out.println(num + " is a pernicious number.");
                42               }

                43               else
                44               {

                45                System.out.println(num + " is NOT a pernicious number.");
                46               }

                47           }
                48       }


              The output of the preceding program is as follows:
                     BlueJ: Terminal Window - Java

                 Options

                Enter a binary number: 1111
                1111 is NOT a pernicious number.


                Program 3      Write a program to input the numbers and print the Pascal's triangle.


                 1       // Print Pascal's Triangle in Java
                 2       import java.util.*;
                 3       class pascals

                 4        {
                 5           int findfactorial(int n)

                 6           {




                  564  Touchpad Computer Science (Ver. 3.0)-XI
   561   562   563   564   565   566   567   568   569   570   571