VGP 3rd 6-Weeks Test Review 20/21
Which operator can be used to compare two values?
==
The value of a string variable can be surrounded by single quotes.
False
How do you create a variable with the numeric value 5?
int x = 5:
What is the correct syntax to output "Hello World" in C#?
Console.WriteLine("Hello World");
Which keyword is used to create a class in C#?
class
How do you create a variable with the floating number 2.8?
double x = 2.8D;
How do you start writing an if statement in C#?
if x > y
Which access modifier makes the code only accessible within the same class?
private
How do you insert COMMENTS in C# code?
string
How do you insert COMMENTS in C# code?
//
What is the expected output of the following program if the user enters 32? using System; public class Exercise11 { public static void Main() { int age; Console.Write("Enter your age "); age = Convert.ToInt32(Console.ReadLine()); Console.Write("You look younger than {0} ",age); } }
Enter your age 32 You look older than 32
What is the expected output of the following program if the user entered -5 and 25? using System; public class Exercise18 { static void Main(string[] args) { Console.WriteLine("\nInput first integer:"); int x = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Input second integer:"); int y = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Check if one is negative and one is positive:"); Console.WriteLine((x < 0 && y > 0) || (x > 0 && y < 0)); } }
True
What is the expected output of the following program? using System; class Program { static void Main(string[] args) { Console.WriteLine(test(30, 0)); Console.WriteLine(test(25, 5)); Console.WriteLine(test(20, 30)); Console.WriteLine(test(20, 25)); Console.ReadLine(); } public static bool test(int x, int y) { return x == 30 || y == 30 || (x + y == 30); } }
True True True False
What would the expected output be if the user entered a, b, c? using System; public class Exercise1 { public static void Main() { char letter1,letter2,letter3; Console.Write("Input letter: "); letter1 = Convert.ToChar(Console.ReadLine()); Console.Write("Input letter: "); letter2 = Convert.ToChar(Console.ReadLine()); Console.Write("Input letter: "); letter3 = Convert.ToChar(Console.ReadLine()); Console.WriteLine(letter3 + " " + letter2, + " " + letter1); } }
c b a
Which operator is used to add together two values?
The + sign