Midterm CSC145

What is the output of the following code?
System.out.print(11/4.0);
Click the card to flip 👆
1 / 42
Terms in this set (42)
What is the output? System.out.print(11 % 4);3What type of program is typically used to translate a program written in a high-level language into machine language?compilerWhich one of the sentences below is syntactically correct, while semantically incorrect?Apples are usually pink or purple.Which of the following packages is automatically loaded into every Java program?java.langWrite Java statements that do the following: Declare int variables x and y. Initialize x to 25 and y to 18. (Please only give the requested statements. Do NOT write a complete program.)int x; int y; x = 25; y = 18;Write a Java statement that does the following: Copy the value of an int variable firstNum into an int variable num. (Assume that both variables have already been declared, and the firstNum variable has already been initialized.) (Please only write a single statement.)num = firstNum;Write Java statements that do the following: Declare an int variable num. Assign the value 5 to the num variable. Output the value of the num variable. (Please only give the requested statements. Do NOT write a complete program.)int num; num = 5; System.out.println(num);Declare a named constant of type byte with the value 100 called MAX. (Please only write a single statement.)final byte MAX = 100;Write a Java statement that does the following: Declare and initialize a named constant PAY_RATE to 18.35. The data type should be double. (Please only write a single statement.)final double PAY_RATE = 18.35;Create an object called oak whose data type is Tree using the class's default constructor.Tree oak = new Tree();Write a single statement that prints the first character of a String object called name. Use the charAt method of the String class, whose signature is shown below.System.out.println(name.charAt(0));Write a single statement that gets the length of a String variable called name and assigns the result to an integer variable called size. Use the length method of the String class, whose signature is shown below. public int length();int size = name.length();Write a single statement that prints the square root of a variable called num. Use the sqrt method of the Math class, which is shown below. public static double sqrt(double a);System.out.println(Math.sqrt(num));Assume that there is a static method called printReverse inside of a class called StringUtil that takes an array of Strings as a parameter and prints the elements of the array in reverse order. Also assume that you have an array of Strings called names. Write a statement that would call the printReverse method to print the names array.StringUtil.printReverse(names);What is the output of the following code? int x = 50; if(x<100 && x>100) { System.out.println("yes"); } else { System.out.println("no"); }noWhat is the output of the following code? int x = 50; if(x<100 || x>100) { System.out.println("yes"); } else { System.out.println("no"); }yesWhat is the output of the following code? int x = 50; if(x!=50) { System.out.println(x); }There is no output.What is the output of the following code? int x = 50; if(x==50) { System.out.println(x); }50What's wrong with the following code? while(x=10) System.out.print("A");wrong operatorWhat is the output of the following code? for(int i=1; i<=8; i++) { System.out.print(i); }12345678What is the output of the following code? for(int i=1; i<=10; i++) if(i%2 == 0) System.out.print(i);246810What is the output of the following code? int i=1; while(i<=8) { if(i%2 != 0) System.out.print(i); i++; }1357Write a "while" loop that prints the first ten multiples of 5 as shown below: 5 10 15 20 25 30 35 40 45 50 (Please only write the requested loop, including the initialization of the loop control variable. Do NOT write a complete program.)int i = 5; while(i <= 50) { System.out.print(i + " "); i += 5; }Write a "for" loop that prints the first four multiples of 5 in reverse order as shown below: 20 15 10 5 (Please only write the requested loop. Do NOT write a complete program.)for(int i = 4; i > 0; i--) System.out.println(i * 5);What do we call a value stored in an array?elementWhich of the following is an array property that represents the number of elements in the array?lengthWhat term is used for an integer that is used to identify a specific element in an array?indexThe following code contains a loop that should print each element of the values array. What is the error? int[] values = { 1, 2, 3, 4, 5 }; for(int i=0; i<=5; i++) System.out.println(values[i]);The loop ends at i=5, but it should end at 4.Write a statement that assigns the character 'A' to the first element of an array called grades.Write a statement that declares an array of characters called letters and uses the new keyword to initialize the array so that it can hold 5 characters.Write a single statement that declares an int array called values and initializes the array's elements to the first three positive integers 1 through 3.Write a loop that prints the elements of an integer array called costs. For this question, use the "for each" style of loop.