1 / 2100%
CSE 110 Fall 2015
©Kanika Grover Page 1
LastName ____________________FirstName__________________Class Time____________
Class Activity 4 Maximum Points:10
public class MyDecisionClass
{
public static void main(String[] args)
{
int value1 = 8;
int value2 = 9;
int value3 = 10;
if(value1+7/3 > value2-1+2)
System.out.printf("Player 1 wins!!\n");
else
System.out.println("Player 2 wins");
// What is the output of the above?_Player 2 wins____
if(Math.sqrt(64) < value3/2+3)
System.out.println(first);
else if(value1 < 10)
System.out.println(second);
else
System.out.println(general case);
// What is the output of the above?___second___
if(value1 < 20)
System.out.println(++value2);
if(value1 < 10)
System.out.println(value3++);
// What is the output of the above?__10___
__10___
if (value3 != value1-8+value2-11)
{
if (value2 < 10)
System.out.println("nested if true!") ;
else
System.out.println("nested if false!") ;
}
else
System.out.println("outside nested branch") ;
// What is the output of the above?__nested if false __
}
}
CSE 110 Fall 2015
©Kanika Grover Page 2
Question: Create a flowchart for the second part (if - else if)
and last part (nested if).
Math.sqrt(64) <
value3/2+3?
first
True
False
Value1 < 10?
True
False
general case
second
Eq = value1-8+value2-11
value3 != Eq?
nested if true
nested if false
True
False
True
Done
False
outside nested
branch
Powered by TCPDF (www.tcpdf.org)
Students also viewed