हिंदी

Observe the following code. It may contain Syntax, Logical or runtime errors. import java.io.* ; class Paper } int fnBox(int limit) { for(int sum = 0, t= 1; t <= limit;t++) sum = sum + t; return sum;

Advertisements
Advertisements

प्रश्न

Observe the following code. It may contain Syntax, Logical or runtime errors. Execute it in Java and identify the error, if any. Rewrite the code without the error. Also write the aim of the code.

import java.io.*;
class Paper
}
   int fnBox(int limit)
   {
      for(int sum = 0, t= 1; t <= limit;t++)
              sum = sum + t;
      return sum;
   }
   void main()
   {
      int N;
      Scanner sc = new Scanner(System.in);
      System.out.print("Enter limit:");
      N = sc.nextInt();
      System.out.print("Result=" + fnBox(N));
   }
}
कोड लेखन
Advertisements

उत्तर

import java.io.*;
import java.util.*;
class Paper
}
   int fnBox(int limit)
   {
      for(int sum = 0, t= 1; t <= limit;t++)
              sum = sum + t;
      return sum;
   }
   void main()
   {
      int N;
      Scanner sc = new Scanner(System.in);
      System.out.print("Enter limit:");
      N = sc.nextInt();
      System.out.print("Result=" + fnBox(N));
   }
}
shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 3: User-Defined Methods - Exercises [पृष्ठ ९४]

APPEARS IN

रुपा पंडित Computer Applications [English] Class 10 ICSE
अध्याय 3 User-Defined Methods
Exercises | Q 7. (x) | पृष्ठ ९४
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×