Java Training in Chennai – Data Types, Variables and Operators Puzzles with Answers – Part – II 

 Here in this blog we are discussing about Java Training in Chennai – Data Types, Variables and Operators Puzzles with Answers – Part – II . Some of them are discussed below .

    We have already discussed about this topic in the previous blog ” Java Training in Chennai – Data Types, Variables and Operators Puzzles with Answers – Part – I

_______________________________________________________________________________

What will be the output of the following program? Assume that the argument passed as – Payilagam.

public class MyName {

public static void main(String args[]) {

if (args.length == 0 || args[0].equalsIgnoreCase(“Payilagam“)) {

System.out.println(“I Dont Know”);

} else {

System.out.println(args[0]);

}

}

}

 

What will be the output of the following program?

class Test1

{

public static void main(String s[])

{

float f = 75.0f;

double d = 75.0;

int i = 75;

if( f == d )

{

if( f == i )

{

System.out.println(“f, d and i are equal”);

}

else

{

System.out.println(“f, d are equal but i is not equal”);

}

}

else

{

System.out.println(“f and d are not equal”);

}

}

}

 

class DetermineGroup

{

public static void main(String s[])

{

boolean male = false;

int age = 30;

if( male )

if( age < 20 )

System.out.println(“Boy”);

else

System.out.println(“Man”);

else

if( age < 20 )

System.out.println(“Girl”);

else

System.out.println(“Woman”);

}

}

 

class DetermineGroup

{

public static void main(String s[])

{

boolean male = false;

int age = 30;

if( male )

if( age < 20 )

System.out.println(“Boy”);

else

System.out.println(“Man”);

else

if( age < 20 )

System.out.println(“Girl”);

else

System.out.println(“Woman”);

}

}

 

class StudentPass

{

public static void main(String s[])

{

int marks = 80;

if( marks > 70 )

System.out.println(“Distinction”);

System.out.println(“Congratulations”);

else if( marks > 35 )

System.out.println(“Pass”);

else

System.out.println(“Fail”);

System.out.println(“Better luck next time”);

}

}

 

public void output(boolean a, boolean b) {

if (a && b) {

System.out.println(“A && B”);

} else if (a) {

System.out.println(“A”);

} else {

if (!b) {

System.out.println(“notB”);

} else {

System.out.println(“ELSE”);

}

}

}

 

class WeekDays

{

public static void main(String s[])

{

int day = 7;

switch(day)

{

case 1:

System.out.println(“Monday”);

case 2:

System.out.println(“Tuesday”);

case 3:

System.out.println(“Wednesday”);

case 4:

System.out.println(“Thursday”);

case 5:

System.out.println(“Friday”);

}

}

}

 

class NumberDescription

{

public static void main(String s[])

{

int number = 5;

switch(number)

{

case 2:

case 4:

case 6:

case 8:

System.out.println(“Even”);

break;

case 1:

case 3:

case 5:

case 7:

case 9:

System.out.println(“Odd”);

break;

case 2:

case 3:

case 5:

case 7:

System.out.println(“Prime”);

break;

case 4:

case 9:

System.out.println(“Perfect Square”);

break;

default:

System.out.println(“Can only describe numbers from 1 to 9”);

}

}

}

 

class HappyNewYear

{

public static void main(String s[])

{

int code = 3;

switch(code)

{

case 1:

System.out.println(“Wish”);

case 2:

System.out.println(“You”);

default:

System.out.println(“A”);

case 3:

System.out.println(“Happy”);

case 4:

System.out.println(“New”);

case 5:

System.out.println(“Year”);

}

}

}

 

class Directions

{

public static void main(String s[])

{

char direction = ‘N’;

char west = ‘W’;

switch(direction)

{

case ‘N’:

System.out.println(“North”);

break;

case ‘E’:

System.out.println(“East”);

break;

case west:

System.out.println(“West”);

break;

case ‘S’:

System.out.println(“South”);

}

}

}

 

public class Test {

public static void main(String args[]) {

int i = 1, j = 0;

switch (i) {

case 2 :

j += 6;

case 4 :

j += 1;

default :

j += 2;

case 0 :

j += 4;

}

System.out.println(“j = ” + j);

}

}

 

public class KIs {

public static void main(String args[]) {

int k = 66;

switch (k) {

default :

System.out.print(“Website”);

case 66 :

System.out.print(“Payilagam”);

case ‘k’ :

System.out.print(“Chennai”);

case ‘j’ :

System.out.print(“Java”);

break;

}

}

}

 

public class Prize {

public static void main(String args[]) {

int x = 111, y = 101;

switch (x & y) {

case 1 :

System.out.println(“-1-“);

case 101 :

System.out.println(“-101-“);

case 111 :

System.out.println(“-111-“);

case 010 :

System.out.println(“-010-“);

default :

System.out.println(“-” + x & y + “-“);

}

}

}

 

public class DemoOnSwitch

{

public static void main(String[] args)

{

int var = 12;

switch (var)

{

case 014 :

System.out.print(“Hello”);

break;

case 12 :

System.out.print(“Hi”);

default :

System.out.print(“How are you?”);

}

}

}

 

public class TestSwitch

{

public static void main(String a[])

{

char ch = ‘a’;

switch (ch)

{

case ‘a’ :

case ‘A’ :

System.out.print(ch);

break;

case ‘b’ :

case ‘B’ :

System.out.print(ch);

break;

case ‘c’ :

case ‘C’ :

System.out.print(ch);

break;

case ‘d’ :

case ‘D’ :

System.out.print(ch);

}

}

}

_______________________________________________________________________________

References:

https://payilagam.com/blogs/java-training-in-chennai-data-types-variables-and-operators-puzzles-with-answers/

COURTESY :                                    

                                   www.quizover.com, www.gocertify.comwww.geeksforgeeks.orgwww.developer.com,           

                                    www.meritcampus.comwww.sanfoundry.com , www.javacodeexamples.comwww.jchq.net