Consider 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 DetailsImagine if you were given candies to divide evenly between t…
Imagine if you were given candies to divide evenly between the members of your group of 4. You should follow kindergarten rules, where everyone in the group should get the same number, and any extras should be returned to the teacher.If your group of 4 received 11 candies, how many candies are left over to be returned to your teacher?
Read DetailsAn acronym is formed by extracting the first letter of each…
An acronym is formed by extracting the first letter of each word in a phrase of one or more words. For example, the acronym of the phrase “Laugh Out Loud” is “LOL”, and the acronym of the phrase “If you know you know” is “Iykyk.” A phrase must meet the following conditions. • The phrase has exactly one space between each word. • The phrase does not have leading or trailing spaces. • The final word in the phrase has at least two characters. In the following code segment, the String variable phrase has been properly declared and initialized such that it meets these conditions. The code segment is intended to create the acronym of the String stored in phrase and store it in the variable text. String temp = phrase;String text = temp.substring(0, 1); int i = temp.indexOf(” “);while (i > 0){ /* missing code */} Which of the following can be used to replace /* missing code */ so that the code segment works as intended?
Read DetailsConsider the following code segment. Assume that the int var…
Consider the following code segment. Assume that the int variable input has been properly declared and initialized. int answer = 1; if (input != 0){ int count = 1; while (count != input){ count++; answer *= count; }}System.out.println(answer); Which of the following best describes the condition in which this code segment always results in integer overflow?
Read Details