Q:

Java find output programs (if else) | set 3

belongs to collection: Java find output programs

0

Find the output of Java programs | if else | Set 3: Enhance the knowledge of Java if else concepts by solving and finding the output of some Java programs.

Question 1:

public class Main {
  public static void main(String[] args) {
    int X = 20;
    int Y = 10;
    int Z = 30;

    if (X > Y && X == 10) System.out.println("ABC");
    else if (Z > Y && Z = 20) System.out.println("PQR");
    else if (Z == 30 && Z == 10) System.out.println("XYZ");
  }
}

Question 2:

public class Main {
  public static void main(String[] args) {
    int A = 20;
    float B = 20.0F;

    if (sizeof(A) == sizeof(B)) 
        System.out.println("Hello");
    else 
        System.out.println("Hiii");
  }
}

Question 3:

public class Main {
  public static void main(String[] args) {
    double X = 20.23;
    float Y = 20.23F;

    if (X > Y) System.out.println("India");
    else System.out.println("Australia");
  }
}

Question 4:

public class Main {
  public static void main(String[] args) {
    String STR1 = "INDIA";
    String STR2 = "india";

    if (STR1 > STR2) System.out.println("WWW.INCLUDEHELP.COM");
    else System.out.println("www.includehelp.com");
  }
}

Question 5:

public class Main {
  public static void main(String[] args) {
    String ABC = "INDIA";
    String XYZ = "india";

    if (ABC == XYZ) System.out.println("WWW.INCLUDEHELP.COM");
    else System.out.println("www.includehelp.com");
  }
}

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer Question 1:

Output:

Main.java:8: error: bad operand types for binary operator '&&'
    else if (Z > Y && Z = 20) System.out.println("PQR");
                   ^
  first type:  boolean
  second type: int
1 error

Explanation:

The above program will generate a syntax error.

else if(Z>Y && Z=20)

In the above condition, we used the assignment operator "=" instead of equal to "==" operator. Then it will return an integer value that cannot be used as an operand with the logical end "&&" operator.

Answer Question 2:

Output:

Main.java:6: error: cannot find symbol
    if (sizeof(A) == sizeof(B)) 
        ^
  symbol:   method sizeof(int)
  location: class Main
Main.java:6: error: cannot find symbol
    if (sizeof(A) == sizeof(B)) 
                     ^
  symbol:   method sizeof(float)
  location: class Main
2 errors

Explanation:

The above program will generate syntax errors because the sizeof() operator does not exist in java.

Answer Question 3:

Output:

India

Explanation:

The above program will print "India" on the console screen. Because, X is the double type and Y is float type. In Java, a double number is always treated greater in case of equality. That's why the if condition will true and print "Hello" on the console screen.

Answer Question 4:

Output:

Main.java:6: error: bad operand types for binary operator '>'
    if (STR1 > STR2) System.out.println("WWW.INCLUDEHELP.COM");
             ^
  first type:  String
  second type: String
1 error

Explanation:

The above program will generate syntax error because we cannot use greater than the operator with string operands.

Answer Question 5:

Output:

www.includehelp.com

Explanation:

The above program will print "www.includehelp.com" on the console screen. Because, ABC and XYZ do not contain the same values. That's why condition will false and else part will execute then it will print "www.includehelp.com" on the console screen.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java find output programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java find output programs (switch case) | set 1... >>
<< Java find output programs (if else) | set 1...