Page 287 - ComputerScience_Class_11
P. 287

obj.calculate(10, 30);
                               obj.calculate(20, 35);
                           }
                       }
                    2.  class Armstrong {
                           int n;
                           Armstrong() {
                               n = 0;
                           }
                           void input() {
                               Scanner sc = new Scanner(System.in);
                               System.out.println("Enter a number: ");
                               n = sc.nextInt();
                           }
                           boolean check_armstrong() {
                               int temp = n, sum = 0, rem;
                               int digits = String.valueOf(n).length();
                               while (temp > 0) {
                                   rem = temp % 10;
                                   sum += Math.pow(rem, digits);
                                   temp /= 10;
                               }
                               return n == sum;
                           }
                           void display() {
                               if (check_armstrong())
                                   System.out.println(n + " is an Armstrong Number");
                               else
                                   System.out.println(n + " is not an Armstrong Number");
                           }
                           public static void main(String[] args) {
                               Armstrong ob = new Armstrong();
                               ob.input();
                               ob.display();
                           }
                       }
                    3.  class Counter {
                           static int increase = 0;
                           static void incre() {
                               increase++;
                           }
                           void display() {
                               System.out.println("Counter:" + increase);
                           }
                           public static void main(String[] args) {
                               Counter ob1 = new Counter();




                                                                                           Methods and Constructors  285
   282   283   284   285   286   287   288   289   290   291   292