Advertisements
Advertisements
Question
Given below is the program with errors in it. Identify the errors. Rewrite the program and predict the output.
import java.util.*
class Program
{
int A, B, C;
Scanner sc = new Scanner.System.in;
System.out.print("\n Enter the value of A: ");
A = sc.nextInt();
If (A % 10=0 )
{
System.out.println(" A is an Even number ");
else
{
System.out.println(" A is an Odd number ");
}
}
}Code Writing
Advertisements
Solution
import java.util.*;
class Program
{
void main()
{
int A, B, С;
Scanner sc=new Scanner(System.in);
System.out.print("\n Enter the value of A:");
A = sc.nextInt();
if (A % 2=0)
{
System.out.println(" A is an Even number");
}
else
{
System.out.println(" A is an Odd number");
}
}
}
To test if a number is even or odd.
shaalaa.com
Is there an error in this question or solution?
Chapter 1: Revision of Class 9 Syllabus - Exercises [Page 47]
