Provide two alternatives (1 for loop and 1 while loop) to the loop in fig. 5.12 that does not change the programs output but also does not use a "break" statement. Modify the sample code below to have a single return statement. Prepare all three modifications in a Word document with a discussion as to why using break in this way as well as using multiple return statements is not considered good programming form by most in the field.
Sample Code:
public boolean isTheFirstOneBigger(int num1, int num2)
{
if (num1 > num2)
{
return true;
}
if (num1 <= num2)
{
return false;
}
}
1
Expert's answer
2012-03-30T09:43:01-0400
Variant 1: for loop
public static boolean isTheFirstOneBigger(int num1, int num2){ for(;;) if(num1>num2) return true; else return false; }
Variant 2: while loop
public static boolean isTheFirstOneBigger(int num1, int num2){ while(num1>num2) return true; return false; }
Bonus variant (not required)
public static boolean isTheFirstOneBigger(int num1, int num2){
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments
Leave a comment