Question

bcswebdav/pid-6788375-dt-content-rid-73446427 2/courses/2182-INTRO-COMPUTERS--PROGRAMMING Write for each letter (a-c) Yes, the If statement will execute or No, the if statement will not execute depending on the variables given. the statement does not execute, explain why. Use the same Answers document used in problem 1. while(((num!--num3 Ⅱ break; a) int num1-3; int num2 4; int num3-5; String firstemoon: String second sun; String third-moon; b) int num1-3; int num2-4 int num3-5; String first- dog String second-sun; String thirdmoon: c) int num1-3; int num2-3; int num3-3; String first-cat; String second- cat String thirdamoon: MacBook Air
0 0
Add a comment Improve this question Transcribed image text
Answer #1

a)

public class MyClass {

    public static void main(String args[]) {

        int num1=3;

        int num2=4;

        int num3=5;

       

        String first="moon";

        String second="sun";

        String third="moon";

       

        while(((num1==num3||num2==num3)&&first.equals(second)||first.equals(third))||(first.equals(third)&&num3==num1))

        {

        System.out.println("Hello" );

        break;

    }

    }

}

Output

Hello

Explanation

Here the while statement below evaluates as follows . Here F indicates False and T indicates True.

(((num1==num3||num2==num3)&&first.equals(second)||first.equals(third))||(first.equals(third)&&num3==num1))

=(((F||F)&&F||T)||(T&&F))

=((F&&F||T)||(T&&F)

=((F||T)||(T&&F))

=(T||F)

=True

Here while evaluates to true and hello in the loop is printed.

b)

public class MyClass {

    public static void main(String args[]) {

        int num1=3;

        int num2=4;

        int num3=5;

       

        String first="dog";

        String second="sun";

        String third="moon";

       

        while(((num1==num3||num2==num3)&&first.equals(second)||first.equals(third))||(first.equals(third)&&num3==num1))

        {

        System.out.println("Hello" );

        break;

    }

    }

}

Output

Explanation

Here the while statement below evaluates as follows . Here F indicates False and T indicates True.

(((num1==num3||num2==num3)&&first.equals(second)||first.equals(third))||(first.equals(third)&&num3==num1))

=(((F||F)&&F||F)||(F&&F))

=((F&&F||F)||(F&&F)

=((F||F)||(F&&F))

=(F||F)

=False

Here while evaluates to false and nothing is printed as output.

c)

public class MyClass {

    public static void main(String args[]) {

        int num1=3;

        int num2=3;

        int num3=3;

       

        String first="cat";

        String second="cat";

        String third="moon";

       

        while(((num1==num3||num2==num3)&&first.equals(second)||first.equals(third))||(first.equals(third)&&num3==num1))

        {

        System.out.println("Hello" );

        break;

    }

    }

}

Output

Hello

Explanation

Here the while statement below evaluates as follows . Here F indicates False and T indicates True.

(((num1==num3||num2==num3)&&first.equals(second)||first.equals(third))||(first.equals(third)&&num3==num1))

=(((T||T)&&T||F)||(F&&T))

=((T&&T||F)||(F&&T)

=((T||F)||(F&&T))

=(T||F)

=True

Here while evaluates to true and hello in the loop is printed.

Add a comment
Know the answer?
Add Answer to:
bcswebdav/pid-6788375-dt-content-rid-73446427 2/courses/2182-INTRO-COMPUTERS--PROGRAMMING Write for each letter (a-c) Yes, the If statement will execute" or "No, the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT