Answer:
The correct option is option 3 which is The code segment works as intended but only when the sum of the three lengths is an integer or the decimal part of the sum of the three lengths is greater than or equal to 0.5.
Explanation:
As the variable minLength is defined as an integer thus the value is being truncated although the value of 0.5 is being added however if the decimal portion of the length is less than 0.5, the portion is truncated.
Answer:
A pre-programmed function is a section of code which is reusable to perform certain routine. One benefit of using a pre-programmed function to analyze data is the code redundancy can be reduced. The function is only written for once and it can be called to perform a specific data analysis whenever it is needed.
Besides, a pre-programmed function also offer consistent analytical output as all data are processed by a same analytical procedure in the function.
Answer:
import java.util.*;
public class Main {
public static void main(String[] args)
{
Scanner scan = new Scanner();
double budget=0, num=0, total=0;
System.out.println("Your budget for the month? ");
budget=scan.nextDouble();
System.out.println("enter all expense, and after that type -9999 to quit: ");
while(num != -9999)
{
total+=num;
num=scan.nextDouble();
}
if(total<=budget)
{
System.out.println("under budget by ");
System.out.println(budget-total);
}
else
{
System.out.println("over budget by ");
System.out.println(total-budget);
}
}
}
Explanation:
- Take the budget as an input from user and store it to the budget variable.
- Loop until user has entered all his expenses and keep on adding them to the total variable.
- Check If the total is less than or equal to budget or otherwise, and then print the relevant message accordingly.
Answer:
D. Algorithms of simple problems are readily available for reference.
Explanation:
Hope this helps you! Ask me anything if you have any quistions!