3. If/Else Simulation
What Output Does The Following Code Produce?
int x = 7;
int y = 5;
int z = 1;
if (x >= y) {
Console.WriteLine(“You Totally Got This!”);
if (z < y) {
x = y;
z = x;
z = 7;
}
}
Console.WriteLine(“The value of x, y, z: ” + x + “ ” + y + “ ” + z);
You Totally Got This!
The value of x, y, z: 5 5 7
5. Fix The Errors
public class amiright {
public void string[]args {
identifier = ‘TINA’;
Symbol = ‘’r”;
int age = 78;
CallME(78);
}
static void CALLME(identifier,int age) {
Console.WriteLine(My name is name identifier and I am age years
old.);
}
}
9. Given a Problem, Write The Code
Write Code that:
1. Generates 3 random numbers within the range of 12 to 100
2. If the sum of the 3 numbers is divisible by 4…
a) set variable y to 4;
b) print “I’m divisible by 2” 2 times
3. If the number is divisible by 2…
a) set variable x to 12
b) print “I’m divisible by 4” 4 times
4. Otherwise, print “I’m boring” 5 times
17. Given a Problem, Write The Code
Write a static method named xo that accepts an integer size as a parameter and
prints a square of size by size characters where ‘x’ is the first and last character on
each line and ‘o’ is inside size number of times.
Example 1:
xo(5);
Output:
xooooox
xooooox
xooooox
xooooox
xooooox
Example 2:
xo(3);
Output:
xooox
xooox
xooox
Example 3:
xo(1);
Output:
xox