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.
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...
c++ U CHU PO J O ! Week 11 Homework-Functions X + /bbcswebdav/pid-2592362-dt-content-rid-39864984_1/courses/CSC-170-03-191/CSC%20170%20Program%205%20%26% CSC 170 - 03 Fall 2019 Program 5 & 6 You are required to write a program which reads five test scores and computes and prints the sum and average of these test scores. Note: This program should not use arrays. You are required to produce two versions of this program Version 1 Program 5 In the first version you must use the following: 1. Avoid function...