Computer Applications
Predict the output of the given snippet, when executed:
int b=3,k,r;
float a=15.15,c=0;
if(k==1)
{
r=(int)a/b;
System.out.println(r);
}
else
{
c=a/b;
System.out.println(c);
Java
Input in Java
59 Likes
Answer
Syntax Error
Working
There are 2 syntax errors in this program:
- Variable k is not initialized with any value before using it in the if check.
- The closing curly brace is missing for the compound statement block of else part.
Answered By
37 Likes
Related Questions
State whether the following statement is True or False :
In an if-else statement, the condition is to be defined only with if and not with else.
Predict the output of the given snippet, when executed:
int x = 1,y = 1; if(n > 0) { x = x + 1; y = y + 1; } System.out.println(x + " , " + y);
What will be the values of x and y, if the value of n is given as:
(i) 1
(ii) 0 ?Correct the errors of the given program:
class public { public static void main(String args{}) { int a=45,b=70,c=65.45; sum=a+b; diff=c-b; System.out.println(sum,diff); } }
class Simplify { public static void main(String args[]) { int a,b,c,d; a=10,b=5,c=1; c=2a+2b; d=(a+b)2; p=c/d; System.out.println(c , d , p); } }