Week1 Basic Java Practice questions – Control Structures
D. JHASHMI
RA2311003011617
Section: G2
1.Even or Odd Number Check
ALGORITHM:
1. Start
2. Prompt the user to enter a number.
3. Read the input number.
4. Convert the input to an integer.
5. Check if the number divided by 2 has a remainder 0.
6. End
PROGRAM:
import java.util.Scanner;
public class Question1 {
public static void main(String[] args) {
int num;
Scanner sc = new Scanner(System.in);
System.out.println("Enter number:");
num = sc.nextInt();
if (num % 2 == 0) {
System.out.println("The number is even");
else{
System.out.println("The number is odd");
}
}
2.Age Verification:
ALGORITHM:
1. Start
2. Prompt the user to enter their age.
3. Read the input age.
4. Convert the input to an integer.
5. Check if the age is 18 or above.
6. End
3.Vending Machine (Single Choice):
ALGORITHM:
1. Start
2. Display a message “Press 1 for juice or 2 for
soda.”
3. Prompt the user to enter their choice.
4. Check the choice.
5. End.
4. Temperature Check:
ALGORITHM :
1. Start
2.
Initialize
the
variables.
3. Read
User
Input.
4. Check Temperature and Print Message.
5. End
5. Positive, Negative, or Zero:
ALGORITHM:
1. Start
2. Initialize the variables.
3. Display Prompt.
4. Read User Input.
5. Check number and print message.
6. End
6.Grading System:
ALGORITHM:
1. Start
2. Initialize the variables.
3. Display Prompt.
4. Read User Input.
5. Determine Grade using Switch Statements.
6. Print the grade.
7. End
7. Simple Calculator:
ALGORITHM:
1. Start
2. Display Prompt for operation choice.
3. Read User Choice.
4. Perform Operation based on Choice.
5. Close the scanner.
6. End
8. Leap Year Check:
ALGORITHM :
1. Start
2. Initialize the variable.
3. Display Prompt.
4. Read user Input.
5. Determine if the Year is a Leap year.
6. End