English

Given the following program, identify the local variable, instance variable and argument variable .importjava.util.*; class Factor { int N; void fnIsFactor(int f) { if (N%f =0)

Advertisements
Advertisements

Question

Given the following program, identify the local variable, instance variable and argument variable. 

importjava.util.*;
class Factor
{
    int N;
    void fnIsFactor(int f)
    {
       if (N%f =0)
       {
          System.out.print(f +" is a Factor of "+ N);
       }
       else
       {
          System.out.print(f + " is a Not a Factor of "+ N);}
       }
    }
    void fnAllFactors()
    {
       int r = 0;
       System.out.println("\n Factors of " + N);
       for(r = 1; r <=N; r++)
       {
         if (N % r =0)
         {
           System.out.print(r + "");
         }
       }
    }
    void main()
    {
         Scanner sc = new Scanner(System.in);
         System.out.println("Enter value for N :");
         N = sc.nextInt();
         System.out.println("Enter value for L :");
         int L = sc.nextInt();
         fnIsFactor(L);
         fnAllFactors();
    }
}
Very Short Answer
Advertisements

Solution

N - instance variable

f - argument, formal variable

r - local variable

sc - object/variable of scanner class

L - local variable

shaalaa.com
  Is there an error in this question or solution?
Chapter 6: Encapsulation - Exercises [Page 149]

APPEARS IN

Rupa Pandit Computer Applications [English] Class 10 ICSE
Chapter 6 Encapsulation
Exercises | Q 4. | Page 149
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×