WorksheetsClass 8 Program coding Java
Total questions: 13
Worksheet time: 7mins
All functions and variables in Java language are kept inside a?
Who invented Java?
James Gosling
Sergey Brin
Steve Jobs
Bill Gates
Tim Berners-Lee
public void main()
{
double temp = 56.0;
if (temp <=54.0 && temp>40)
System.out.println(“It is too hot”);
else if ( temp<40 || temp>30)
System.out.println(“It is hot but not too much”);
else
System.out.println(“It is pleasant”);
}
What will be the output?
It is too hot
It is pleasant
It is hot but not too much
runtime error
PREDICT THE OUTPUT:
int x = 20;
int y = 18;
if(x>y)
System.out.println("x is greater than y");
else
{
System.out.println("Error");
System.out.println("Incorrect code");
}
Error
Incorrect code
x is greater than y
Error
Incorrect code
PREDICT THE OUTPUT:
int x = 60;
int y = 90;
if (y%x == 0 && y-x==30)
{
System.out.println("Hello World");
}
else
{
System.out.println("Error")
}
Hello World
Hello World
Error
Error
Hello world
If a, b and c are the sides of a triangle then which of the following statement is true for:
if(a==b && a==c && b==c)?
Equilateral triangle
Scalene triangle
Isosceles triangle
All of the above
Condition is essentially formed using:
Arithmetic operators
Relational operators
Logical operators
None
Which of the following is a conditional statement?
if
if else
if else if
all of the above
A Java program executes but doesn’t give the desired output. It is due to:
logical error
syntax error
run time error
none
The if -else statement executes a block of code if a specified condition is
true
false
both
none
