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 [पृष्ठ ४७]
