This question is intended to test your knowledge of the Java data types specifically int, char and String. You may review these types before answering the question. Pick the best applicable answer Question: What is the data type of the following value: '2' | int | | | char | | | String | | | None of the above | | |
#6. Java data types... | |
This question is intended to test your knowledge of the Java data types specifically int, char and String. You may review these types before answering the question. Pick the best applicable answer Question: What is the Java data type of the following value: "123" | int | | | char | | | String | | | None of the above | | |
#7. Java data types... | |
This question is intended to test your knowledge of the Java data types specifically int, char and String. You may review these types before answering the question. Pick the best applicable answer Question: What is the data type of the following value: '123' | int | | | char | | | String | | | None of the above | | |
#8. String concatenation... | |
In Java, two strings may be joined (concatenated) together to yield one string. What is the operator for String concatenation in Java? | String.join | | | add | | | join | | | + | | | None of the above | | |
#9. String and number concatenation... | |
Answer true or false: In Java, the + operator may be used to concatenate a string and a number, for example, String x = "Your score is: " + 80.0; |
#10. String and number concatenation... | |
Pick the best applicable answer. In Java, what is the result of the following expression? "123"+5 | 128 | | | "128" | | | 1235 | | | "1235" | | | None of the above | | |
#11. String methods... | |
The String class has several methods that perform operations on the data or value associated with the String. Some of those methods are length, equals, equalsIgnoreCase, toLowerCase and toUpperCase. Which of the following statements would be INCORRECT in Java? | "Gus Ikeji".length() would be 9 | | | Given: String name="John Doe"; name.toUpperCase() would be "JOHN DOE" | | | Given: String name="John Doe"; name.equals("John") would be false | | | Given: String name="John Doe"; name.equalsIgnoreCase("JOHN DOE") would be true | | | None of the above | | |
#12. String methods... | |
The String class has several methods that perform operations on the data or value associated with the String. Some of those methods are trim, charAt, substring, and indexOf Which of the following statements would be INCORRECT in Java? | "Gus Ikeji".trim() would be "Gus Ikeji" | | | Given: String name="John Doe"; name.charAt(1) would be 'o' | | | Given: String name="John Doe"; name.substring(2, 6) would be "hn D" | | | Given: String name="John Doe"; name.indexOf("ohn") would be 1 | | | None of the above | | |
#13. Escape sequence... | |
Programming languages typically have what is called escape sequences. Escape sequences is a special way to represent a character in your program because the normal method of just typing the character would give the wrong outcome. For example, you have the string "JohnDoe" and would like to have the "John" on one line and "Doe" on the next line. You may try "John Doe" but this is incorrect because in Java, a string can not be extended beyond one line. However, you can get the same effect by inserting the escape sequence between "John" and "Doe" as in "John Doe" Java escape sequences start with a backslash \ and then followed by another character e.g. is for a new line \" is double quote \' is for a single quote \t is for tab \\ is for a backslash Question: Which of the following is INCORRECT in Java? | System.out.print("John Doe"); will print John and then on the next line Doe | | | System.out.print("Obi\'s big shoes"); will print Obi's big shoes | | | System.out.print("Hello\tWorld!"); will print Hello, followed by tab-spacing and then World! | | | System.out.print("He answered \"yes\""); will print He answered "yes" | | | None of the above | | |
#14. Unicode character set... | |
Programming languages may limit the scope of values assigned to the character data types to either the ASCII character set or Unicode character set. Java uses the Unicode character set. For the Java programming language, which of the following statements is INCORRECT about the Unicode character set in comparison to the ASCII character set | The ASCII character set represents more characters than the Unicode character set | | | It may require more memory to store a Unicode character than it would take for ASCII character | | | A variable of type char in Java will have memory space 2-bytes long and may be used to store a Unicode character. | | |
#15. To print or println... | |
The System.out object in Java has two methods print and println for screen output. This question relates to the differences between print and println. Which of the following is CORRECT in Java? Pick the best applicable answer | If you want to output multiple values to the screen at different locations in your program, however you want all the output values to appear on one line, you should use the println method each time. | | | If you want to output multiple values to the screen at different locations in your program, however you want all the output values to appear on one line, you should use the print method each time. | | |
#16. nextInt, next and nextLine differences... | |
The Scanner class in Java has several methods for reading values entered from the keyboard. The methods include next, nextInt, and nextLine. Which of the following statements is INCORRECT about the methods? Pick the best applicable answer | Assuming that the user has typed: Hello World! If you invoke the next method for the first time, it will return the string "Hello", and if you invoked next method for the second time, it will return the string "World!" | | | If you want to read two integers (int data type) from the keyboard using the nextInt method, the input may be two int values separated by one or more white spaces such as blank, tab or new line. | | | The nextLine method will read all characters from the point of stoppage for the last read item to the end of the line including the new-line ' ' character. This means that the next read would start with the next input line. In addition, the value returned by the nextLine method would include the ' ' character from the end of the line. | | | None of the above | | |
#17. Type casting... | |
In programming, type casting is a means of changing a value from one data type to another. Given the following statements in Java: int n; double x; Question: Assuming that x has been initialized, what is the Java statement to type cast x from double to int and place the new value into n? Your answer should start with n = |