Page 370 - ComputerScience_Class_11
P. 370

16              sma=number[0];
                17              for(i=1; i<5; i++)

                18              {
                19                  if(number[i]>lar)
                20                      lar=number[i];

                21                  if(number[i]<sma)

                22                      sma=number[i];
                23              }
                24              System.out.println("Largest Number: "+lar);

                25              System.out.println("Smallest Number: "+sma);
                26          }

                27      }

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

                   Options
                  Enter a number: 20

                  Enter a number: 10
                  Enter a number: 30
                  Enter a number: 40

                  Enter a number: 50
                  Largest Number: 50
                  Smallest Number: 10





                Program 6      Write a program to input 5 numbers in an array and print the sum of all the Armstrong
                               numbers in the array. An Armstrong number is a number whose sum of the cubes of the
                               digits is the same as the number.
                1       import java.util.*;

                2       class ArmstrongNumbers  {

                3           public static void main(String[] args)
                4           {
                5               Scanner sc= new Scanner(System.in);

                6               int ar[ ]=new int[5];

                7               int i, t, r, sum=0,sum1=0;
                8               for (i=0; i<5; i++)






                  368  Touchpad Computer Science (Ver. 3.0)-XI
   365   366   367   368   369   370   371   372   373   374   375