WorksheetsC# Operators
Total questions: 25
Worksheet time: 50mins
You are writing a program to determine if a user's input int age is eligible for a senior discount (age 60 or older). Which of the following conditions would you use?
age > 59
age >= 60
age == 60
age < 60
You have two variables int x = 10; and int y = 5;. You want to check if x is greater than twice the value of y. Which of the following expressions should you use?
x > 2 * y
x == 2 * y
x < 2 * y
x >= 2 * y
You are developing a program to compare two strings string str1 and string str2. You want to check if str1 is lexicographically greater than str2. Which of the following expressions would you use?
str1 > str2
str1 == str2
str1 < str2
str1 != str2
You have a boolean variable bool isRainy = true; and want to check if it's not raining. Which of the following expressions should you use?
isRainy
!isRainy
isRainy == true
isRainy != false
You are validating user input for a positive integer int num. You want to ensure that num is greater than zero. Which of the following conditions would you use?
num >= 0
num == 0
num < 0
num > 0
In a game, you want to check if the player's score int playerScore is at least 100 points to qualify for the next level. Which of the following conditions should you use?
playerScore > 100
playerScore >= 100
playerScore == 100
playerScore < 100
You have two variables double price = 25.50; and double budget = 50.00;. You want to check if the price is within the budget. Which of the following expressions should you use?
price == budget
price >= budget
price > budget
price <= budget
You are implementing a login system and want to verify if the entered password string userPassword matches the stored password. Which of the following expressions would you use?
userPassword != storedPassword
userPassword > storedPassword
userPassword == storedPassword
userPassword < storedPassword
You are developing a program to determine if a given number int num is an odd number. Which of the following conditions would you use?
(num % 2) == 0
(num % 2) != 0
(num % 2) > 0
(num % 2) < 0
You are designing a survey and want to ensure that the user's age int age is between 18 and 65 (inclusive) to participate. Which of the following conditions should you use?
age > 18 || age < 65
age == 18 || age == 65
age >= 18 && age <= 65
age < 18 || age > 65
Which of the following is the logical AND operator in C#?
||
!
|
&&
In C#, which logical operator is used for logical OR?
&&
||
!
&
You have two boolean variables bool isSunny = true; and bool isWarm = false;. What will be the result of the expression isSunny && isWarm?
True
False
The code will not compile.
It will throw an exception.
Which of the following is the logical NOT operator in C#?
!!
!
!=
&&
You are developing a program to check if a user's input int age is outside the range of 18 to 65 (exclusive). Which logical operator(s) would you use?
age > 18 || age < 65
age < 18 && age > 65
age >= 18 && age <= 65
age <= 18 || age >= 65
In C#, you have two boolean values bool a = true; and bool b = false;. What will be the result of the expression a || b?
True
False
The code will not compile.
It will throw an exception.
You want to check if a number int num is both greater than 10 and less than 20. Which logical operator(s) would you use?
num > 10 || num < 20
num > 10 ! num < 20
num > 10 && num < 20
num >= 10 && num <= 20
You are implementing a login system and want to grant access if either the user's password is correct or they have an administrator role. Which logical operator(s) would you use?
passwordCorrect && administratorRole
passwordCorrect || administratorRole
!passwordCorrect || !administratorRole
passwordCorrect ! administratorRole
In C#, you have two boolean variables bool x = true; and bool y = true;. What will be the result of the expression x && !y?
True
False
It will not compile.
It will throw an exception.
You have a list of students' ages, and you want to find the students who are not teenagers (age 20 or above). Which logical operator(s) would you use?
age < 20 && age > 20
age <= 20 || age >= 20
age > 20 && age < 20
age >= 20
You are creating a program to check if a user's input int age is eligible for various discounts. If the age is 5 or younger, the discount is "Child"; if the age is between 6 and 17, the discount is "Student"; otherwise, there is no discount ("None"). What discount would a 25-year-old receive?
The discount will be "Child" for a 25-year-old.
The discount will be "Student" for a 25-year-old.
The discount will be "None" for a 25-year-old.
The code will not compile.
You are developing a program to calculate the remainder of a division operation. The user inputs 17 as the dividend and 5 as the divisor. What would be the result of the expression remainder = dividend % divisor;?
remainder = 2
remainder = 3
remainder = 1
remainder = 4
You are developing a program to calculate the total cost of items in a shopping cart. You have the prices of three items: $10, $20, and $30. What would be the result of the expression totalCost = item1Price + item2Price + item3Price;?
totalCost = 60
totalCost = 70
totalCost = 80
totalCost = 90
In an if-else statement, what is the condition that determines which block of code will be executed?
The code with the highest indentation level
The condition specified after the if keyword
The condition specified after the else keyword
The condition specified after the switch keyword
What is the purpose of the else block in an if-else statement?
To specify an alternate condition to check
To provide a default action if the if condition is false
To specify an additional condition to check in addition to the if condition
To terminate the program
