CSC 216 F09/Survivor: Java Questions
Jump to navigation
Jump to search
Questions
This page contains questions for the game "Survivor: Java".
The questions listed below is followed by answers.
1. True or false, int could hold up to 11 digit of numbers. False, only up to 2147483647. 2. What is the difference between int and double? Int holds integers, while double holds float point numbers. 3. To compile, what file extension should you save all your source codes? They should be saved as .java files. 4. How do you comments in java? By using // and /*..*/ 5. What is the difference between run-time error and logic error? None, they are the same. 6. What is the difference between logic error and syntax error? Syntax error is when the code is written wrong, while logic error is when the program does not do what the programmer programmed it to do. 7. What is wrong with the given code: int class =01; Class is a reserved word, therefore, cannot be used. 8. What is the difference between = and == ? = is used for assigning, and == is used for comparison. 9. What is a parameter? A parameter is an input to a method. 10. True or False, multiple object variables can contain references to the same object. True. 11. What is wrong with the following code: public int calcNum() { num = 99; } Missing a return statement. 12. What keyword should be used when making a constant variable? The keyword “final”. 13. True or false, Boolean can only be three different values. False, only two. 14. What does the % do in java? Calculate the remainder of two numbers dividing. 15. What does n++ do? Increment n by 1. 16. What are roundoff errors? It occurs when numbers are cut short and used for calculation. 17. True or false, the index of an array starts at 1. False, starts at 0. 18. What is the difference between String and char? Char holds only 1 letter, while string can hold many. 19. What does printf do? printf is used to print a formatted content. 20. True or false, Scanner class can be used to read keyboard input in a console window? True. 21. True or false, a static method does not operate on an object? True. 22. What does casting do? It turns values of one type to another. 23. What is the switch statement used for? The switch statement is used as a sequence of if and else statement. 24. What is && and || used for? && is used as an and and || is used as an or in conditional statements. 25. What is De Morgan’s Law? The law tells us that we can simplify expression in which the not operator is applied to terms joined by the && and ||. 26. What is the difference between while and for loops? For loop is used to loop through a known numbers of iterations, while the number of iteration on a while loop is not known. 27. What is an array used for? Storing a set of variable of the same type. 28. What is wrong with the following code: Int I = 0; Int count = 0; While(i<10) { Count++; } It is an infinite loop. 29. What is the result of the following code: Int I = 5; double j = 1.0; System.out.println(i * j); 5.0 30. Why do people use long instead of int? Long holds more numbers than int. 31. What is the purpose of Javadoc? The primary purpose of Javadoc is to provide information for developers who use the classes. 32. Use the statement to specify the value that a method returns to its caller. return. 33. What should you declare all instance fields as? private. 34. True or False, constructors contain instructions to initialize objects. True. 35. What are the two most commonly used number types in Java? int and double. 36. Where would you insert the following statement: public static final double CM_PER_INCH = 2.54; Inside of a class. 37. What is the meaning of the following statement? balance = balance + amount; The statement adds the amount value to the balance value. 38. What is a string? A string is a sequence of characters. Strings are objects of the string class. 39. String positions are counted starting with what number? 0. 40. True or False, the if statement lets a program carry out different actions depending on a condition. True. 41. What is wrong with the following code: if(amount <= balance) newBalance = balance – amount; balance = newBalance; Only the first statement is included inside the if statement. Braces must be used to include both. 42. How do you express “Not equal” as a relational operator? != 43. What is the value of s.length() if s is the string “ “ containing a space? 1. 44. What is wrong with the following code: if(ch == ‘S’ || ‘M’) … You need to write two Boolean expressions such as: if(ch == ‘S’ || ch == ‘M’) … 45. When does the following statement print false? System.out.println(x > 0 || x < 0); When x is zero. 46. True or False, you cannot store the outcome of a condition in a Boolean variable. False, you can store the outcome of a condition in a Boolean variable. 47. What type of statement executes a block of code repeatedly and has a condition control how often the loop is executed? A while statement. 48. What is wrong with the following code: for(int i = 1; i <= years){ if(balance >= targetBalance) i = years + 1; else{ balance = balance * 2; } } You need to increment i in the for loop. 49. Can loops be nested? Yes. 50. A table with rows and columns is a typical type of what kind of loop? A nested loop. 51. What is the Boolean operator for AND? && 52. What is the result of the following code: String greeting = “Hello World”; int luckyNumber = 13; System.out.println(greeting + luckyNumber); 53. What type of error is a violation of the rules of the programming language? Syntax. 54. True or False, a parameter is an input to a method. True. 55. True or False, the method value of a method is a result that the method has computed for use by the code that called it. False. It is the return value. 56. In Java, are numbers objects? No. 57. What does ‘API’ stand for? Application Programming Interface. 58. The constructor name is the same as the class name. Always. 59. What type of coverage is a measure of how many parts of a program have been tested? Test Coverage. 60. What mathematical method is used to calculate the absolute value of a number? Math.abs(x).