Basic Java Lab Exercise Day-4
Duration: 2 Hours
1) What is the output for following code.
public class Demo {
public static void main(String[] args) {
String i = "true";
String j = "false";
if(i == j)
[Link]("Hello ");
else
[Link]("Hi ");
}
}
2) What is the output for the following code.
public class Demo {
public static void main(String[] args) {
String i = "true";
String j = "true";
if(i == j)
[Link]("Hello ");
else
[Link]("Hi ");
}
}
3) What is the output for the following code.
public class Demo {
public static void main(String[] args) {
String i = new String("true");
String j = new String("true");
if(i == j)
[Link]("Hello ");
else
[Link]("Hi ");
}
}
4) What is the output for following code.
public class Demo {
1
public static void main(String[] args) {
byte i = 'A';
byte j = 'A';
if(i==j)
[Link]("Hello ");
else
[Link]("Hi ");
}
}
5) What is the output for the following code.
public class Demo {
public static void main(String[] args) {
byte i = 'A';
byte j = 'a';
if(i==j)
[Link]("Hello ");
else
[Link]("Hi ");
}
}
6) What is the output for the following code.
public class Demo {
public static void main(String[] args) {
byte i = 'A';
byte j = 'A';
if(i!=j)
[Link]("Hello ");
else
[Link]("Hi ");
}
}
7) What is the output for the following code.
public class Demo {
public static void main(String[] args) {
byte i = 'A';
byte j = 'a';
if(i!=j)
[Link]("Hello ");
else
[Link]("Hi ");
2
}
}
8) What is the output for the following code.
public class Demo {
public static void main(String[] args) {
boolean i = true;
boolean j = true;
if(!true == i&&j)
[Link]("Hello ");
else
[Link]("Hi ");
}
}
9) What is the output for the following code.
public class Demo {
public static void main(String[] args) {
boolean i = true;
boolean j = true;
if(!false == i&&j)
[Link]("Hello ");
else
[Link]("Hi ");
}
}
10) What is the out put for the following code.
public class Demo {
public static void main(String[] args) {
boolean i = true;
boolean j = false;
if(!false == i&&j)
[Link]("Hello ");
else
[Link]("Hi ");
}
}
11) What is the output for the following code.
public class Demo {
3
public static void main(String[] args) {
boolean i = true;
boolean j = true;
if(!false == i||j)
[Link]("Hello ");
else
[Link]("Hi ");
}
}
12) What is the output for the following code.
public class Demo {
public static void main(String[] args) {
boolean i = true;
boolean j = false;
if(!false == i||j)
[Link]("Hello ");
else
[Link]("Hi ");
}
}
13) What is the output for the following code.
public class Demo {
public static void main(String[] args) {
boolean i = true;
boolean j = false;
if(!true == i||j)
[Link]("Hello ");
else
[Link]("Hi ");
}
}
14) What is the output for the following code.
public class Demo {
public static void main(String[] args) {
int a = 10;
int b = 20;
if(a<b)
if(b<a)
[Link]("Inner if");
else
4
[Link]("Inner else");
else
[Link]("Outer else");
}
}
15) What is the output for the following code.
public class Demo {
public static void main(String[] args) {
int a = 10;
int b = 20;
if(a<b)
if(b>a)
[Link]("Inner if");
else
[Link]("Inner else");
else
[Link]("Outer else");
}
}
16) What is the output for the following code.
public class Demo {
public static void main(String[] args) {
int a = 10;
int b = 20;
if(a>b)
if(b>a)
[Link]("Inner if");
else
[Link]("Inner else");
else
[Link]("Outer else");
}
}
17) What is the output for the following code.
public class Demo {
public static void main(String[] args) {
int a = 10;
int b = 20;
if(a>b)
if(b>a)
5
[Link]("Inner if");
else
[Link]("Inner else");
else
{
int c = 5;
int d = 6;
if(c<d)
[Link]("else inner if");
else
[Link]("else inner else");
}
}
}
18) What is the output for the following code.
public class Demo {
public static void main(String[] args) {
int a = 10;
int b = 20;
if(a<b)
if(b>a)
{
int c = 5;
int d = 6;
if(c<d)
[Link]("if inner if");
else
[Link]("if inner else");
}
else
[Link]("Inner else");
else
[Link]("Inner if");
}
}
19) What is the output for the following code.
public class Demo {
public static void main(String[] args) {
int a = 10;
6
int b = 20;
if(a<b)
if(b>a)
{
int c = 5;
int d = 6;
if(c>d)
[Link]("if inner if");
else
[Link]("if inner else");
}
else
[Link]("Inner else");
else
[Link]("Inner if");
}
}
20) What is the output for the following code.
public class Demo {
public static void main(String[] args) {
int a = 10;
int b = 20;
if(a>b)
if(b>a)
[Link]("Inner if");
else
[Link]("Inner else");
else
{
int c = 5;
int d = 6;
if(c>d)
[Link]("else inner if");
else
[Link]("else inner else");
}
}
}
7
All the Best