Chapter 5
Chapter 5
Chapter 5
Implementing Conditional Statements in Java 01
LECTURE ACTIVITY
Blanks:
1. Method to take user input for an integer.
2. Predefined syntaxt for Scanner function.
3. Condition to check if the number is positive.
4. Message that indicates the number is positive.
Blanks:
1. Method to take user input for an integer.
2. Condition to check if the number is divisible by 2.
3. Message that indicates the number is even.
4. Message that indicates the number is odd.
Blanks:
1. Method to take user input for the score.
2. Message indicating the grade for scores 90 and above.
3. Condition to check for scores between 80 and 89.
4. Message indicating the grade for scores between 80 and 89.
5. Message indicating the grade for scores between 70 and 79.
6. Message indicating that the student failed.
Blanks:
1. Method to take user input for an integer.
2. Condition to check if the number is positive.
3. Message indicating the number is positive.
4. Condition to check if the number is negative.
5. Message indicating the number is negative.
6. Message indicating the number is zero.
Blanks:
1. Method to take user input for an
integer.
2. Variable used in the switch
statement.
3. Message for case 1 (Monday).
4. Message for case 2 (Tuesday).
5. Message for case 3 (Wednesday).
6. Message for case 4 (Thursday).
7. Message for case 5 (Friday).
8. Message for case 6 (Saturday).
9. Message for case 7 (Sunday).
10. Message for invalid input.
ASSIGNMENT:
ASSIGNMENT:
1. What is the Scanner class in Java?
Define the Scanner class and explain its role in Java programming.
2. How does the Scanner class work?
Explain the process of how the Scanner class reads input from different input
streams such as the keyboard (System.in).
Discuss the syntax for initializing a Scanner object.
3. What types of input can the Scanner class read?
Identify and explain the different methods provided by the Scanner class for
reading various types of input (e.g., nextLine(), nextInt(), nextDouble(),
nextBoolean()).
ASSIGNMENT:
4. What are common use cases of the Scanner class?
Describe scenarios where the Scanner class can be useful in real-world Java programs
(e.g., creating interactive console applications, calculators, form data processing).
5. What are the limitations or challenges when using the Scanner class?
Discuss any known challenges with using the Scanner class, such as handling incorrect
input types or unexpected input from users.
How can these issues be addressed? (e.g., using try-catch blocks to prevent runtime
errors).
6. Provide examples of how the Scanner class can be used in a program.
Write a simple program (with code snippets) that demonstrates how to use the Scanner
class to take user input, such as reading integers, strings, and floating-point numbers.