Computer Applications
Correct the errors of the given program:
class Simplify
{
public static void main(String args[])
{
int a,b,c,d;
a=10,b=5,c=1,d=2;
c=a2+b2;
d=(a+b)2;
p=c/d;
System.out.println(c + " "+ " "+d+ " " +p);
}
}
Input in Java
49 Likes
Answer
Errors in the snippet
- Multiple variable assignment statements cannot be separated by a comma. Semicolon should be used instead.
- Variables a2 and b2 are not defined. They should be a and b.
- The line
d=(a+b)2needs an operator between (a+b) and 2. - Variable p is not defined.
Corrected Program
class Simplify
{
public static void main(String args[])
{
int a,b,c,d;
a=10;b=5;c=1;d=2; //1st correction
c=a+b; //2nd correction
d=(a+b) / 2; //3rd correction
int p=c/d; //4th correction
System.out.println(c + " "+ " "+d+ " " +p);
}
}
Answered By
31 Likes
Related Questions
Write a program to input two unequal numbers. Display the numbers after swapping their values in the variables without using a third variable.
Sample Input: a=23, b= 56
Sample Output: a=56, b=23Write a program to input the temperature in Celsius and convert it into Fahrenheit. If the temperature is more than 98.6 °F then display "Fever" otherwise "Normal".
Write a program to accept marks of a student obtained in 5 different subjects (English, Phy., Chem., Biology, Maths.) and find the average. If the average is 80% or more then he/she is eligible to get "Computer Science" otherwise "Biology".
'Mega Market' has announced festival discounts on the purchase of items, based on the total cost of the items purchased:
Total cost Discount Up to ₹2,000 5% ₹2,001 to ₹5,000 10% ₹5,001 to ₹10,000 15% Above ₹10,000 20% Write a program to input the total cost. Display name of the customer, discount and the amount to be paid after discount.