A store sells rope only in whole-foot increments. Given thre…
A store sells rope only in whole-foot increments. Given three lengths of rope, in feet, the following code segment is intended to display the minimum length of rope, in feet, that must be purchased so that the rope is long enough to be cut into the three lengths. For example, for lengths of 2.8 feet, 3 feet, and 5 feet, the minimum length of rope that must be purchased is 11 feet. For these values, the code segment should display 11. As another example, for lengths of 1.1 feet, 3.2 feet, and 2 feet, the minimum length of rope that must be purchased is 7 feet. For these values, the code segment should display 7. In the following code segment, len1, len2, and len3 are properly declared and initialized double variables representing the three lengths of rope. double total = len1 + len2 + len3; int minLength = (int) (total + 0.5); System.out.print(minLength); Which of the following best describes the behavior of the code segment?
Read DetailsConsider the following code segment. int value = initValue;i…
Consider the following code segment. int value = initValue;if(value > 10){ if(value > 15){ value = 0; } else{ value = 1; }System.out.println(“value = “ + value);} Under which of the conditions below will this code segment print value = 1?
Read DetailsConsider the following code segment. import java.util.Scanne…
Consider the following code segment. import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println(“Enter your name:” ); String name = input.nextLine(); System.out.print(“Hello, ” name); }} What will be the output if the user enters Jack?
Read DetailsAssuming the following declarations: int x = 5, y = 2, z =…
Assuming the following declarations: int x = 5, y = 2, z = 10, temp = 0; What is the output of the following statement? If it causes an error, just type error. If nothing is output, just type no output. if ( y >= x ) { y = z; System.out.println( x + ” ” + y + ” ” + z );}
Read Details