True or False 1. A Scanner class can be used to read in user input. 2. Example s
ID: 3906330 • Letter: T
Question
True or False
1. A Scanner class can be used to read in user input.
2. Example syntax for creating a Scanner to read user input is: Scanner input = new Scanner("System.in");
3. The println() statement can be used to provide a prompt to the user.
4. When using printf(), you can use %d as the format specifier for an int type.
5. An import statement, such as the one to import java.util.Scanner should be the very last line in an application.
6. You should always declare your instance variables as type public.
7. Getters are used to set the value of private instance variables.
8. Your application can use a getter to get the current value of an instance variable of an object that your application has created.
9. You must always have an else part for every ‘ if’ statement.
10. The following code will result in the code repeated while i is less than 5, causing the value of i to be printed out as 5. int i = 0; while (i<5); { i++; } System.out.printf("%d", i);
11. “for” loops can never result in an infinite loop.
12. Pseudocode is helpful for algorithm development.
13. Example syntax for a 3 argument constructor for a Book class that takes an int value, a double, and a String: public Book (int num1, double num2, String name) { bookId = num1; bookPrice = num2; title = name; }
14. Example call to the Book constructor from an application could be: Book myBook = new Book("5", "3.5", "The Rabbit Ran");
15. A no argument default constructor will not be provided automatically by the Java compiler once you have declared your own constructor for a class.
16. Constructors should always have a return type of ‘void’.
17. The eight primitive Java types are: boolean, String, int, char, double, float, long, byte.
18. A UML class diagram can be used to design your class.
19. Relational operators can be used to create the condition for an “if” statement but never a “while” loop.
20. In Java, && represents a Conditional AND operator.
Explanation / Answer
true
false. ‘ if’ statement can be used without else
10. false. The while loop will not execute as ; semicolon is the end of statement
11. false. for loop without condition can result in infinite loop
12. true
13. true
14. false The statement is object instantiation not call, a constructor cannot be called , but invoked automatically.
15. true
16. false. Constructors do not return anything
17. true
18. true
19. false. eg while(i<5)
20. true
Do ask if any doubt. Please upvote.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.