हिंदी

Given below is the program with errors in it. Identify the errors. Rewrite the program and predict the output. import java.util.*; class { main() { int p=0, q=0; Scanner sc = scanner (System.in);

Advertisements
Advertisements

प्रश्न

Given below is the program with errors in it. Identify the errors. Rewrite the program and predict the output.

import java.util.*;
class
{
     main()
     {
        int p=0, q=0;
        Scanner sc = scanner (System.in);
        System.out.print ("Enter p :");
        p = nextInt();
        System.out.print ("Enter q :");
        p = nextInt();
        if(p/q=0)
        {        
           System.out.print(q "is a factor of" p);
        }
        else if
        {
           System.out.print (q "is NOT a factor of" p);
        }
     }
}
कोड लेखन
Advertisements

उत्तर

import java.util.*;
class P3
{
   void main()
   {
      int p=0, q=0;
      Scanner sc = new Scanner(System.in);
      System.out.print("Enter p:");
      p = sc.nextInt();
      System.out.print("Enter q:");
      q = sc.nextInt();
      if(p%q=0)
      {
        System.out.print(q+"is a factor of "+p);
      }
      else
      {
        System.out.print(q+" is NOT a factor of "+p);
      }
   }
}

To verify whether q is a factor of p or not.

shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 1: Revision of Class 9 Syllabus - Exercises [पृष्ठ ४७]

APPEARS IN

रुपा पंडित Computer Applications [English] Class 10 ICSE
अध्याय 1 Revision of Class 9 Syllabus
Exercises | Q 6. (iii) | पृष्ठ ४७
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×