0% found this document useful (0 votes)
56 views

Tutorial 3 Flow of Control (Selection) PDF

This document discusses selection control flow in Java programming through the use of if and switch statements. It provides examples of using if statements to determine logical conditions, compare variables, check data types, and order strings. It also gives problems to write if statements that find the largest of three numbers, determine if a year is a leap year, and correct errors in sample if statements. Finally, it provides code snippets containing if statements and asks to determine the output when given values for variables.

Uploaded by

Huirouuu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

Tutorial 3 Flow of Control (Selection) PDF

This document discusses selection control flow in Java programming through the use of if and switch statements. It provides examples of using if statements to determine logical conditions, compare variables, check data types, and order strings. It also gives problems to write if statements that find the largest of three numbers, determine if a year is a leap year, and correct errors in sample if statements. Finally, it provides code snippets containing if statements and asks to determine the output when given values for variables.

Uploaded by

Huirouuu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

WIX1002 Fundamentals of Programming

Tutorial 3 Flow of Control (Selection)

1. Write statements for each of the following


a. Determine whether 3x8=27.
b. Determine whether an input integer is an odd number or even number.
c. Determine whether a character is a capital letter.
d. Display two strings in alphabetical order ignoring their case.
e. A switch statement that display Sunday, Monday, .., Satudary if the input is 0,
1, …, 6.

2. Correct the error for the following statements.


a.
if (num1 = num2)
System.out.println("Number 1 is equal to number 2.");

b.
if (x > y > z)
System.out.println("x is the largest number");

c.
String s1, s2;
if (s1==s2)
System.out.println("They are equal strings.");
else (s1!=s2)
System.out.println("They are not equal strings.");

d.
if x>0 or y>0;
System.out.println("Either x or y is positive");

3. Write the output for the following statements when x=9 and y=10
a.
if (x < 10)
if (y > 10)
System.out.println("*****");
else
System.out.println("#####");
System.out.println("$$$$$");
b.
if (x < 10) {
if (y < 10)
System.out.println("*****");
else{
System.out.println("#####");
System.out.println("$$$$$");
}}

c.
if (x < 10) {
if (y < 10)
System.out.println("*****");
System.out.println("#####");
}
else {
System.out.println("$$$$$");
}

d.
if (x > 10) {
if (y > 10) {
System.out.println("*****");
System.out.println("#####"); }
else
System.out.println("$$$$$");
}

4. Write the java statements that used the if statement to find the biggest number among
three given integers.

5. Write the java statements that determine whether the Leap year. A Leap year is
divisible by 4 but not by 100. However, a Leap year is also divisible by 400.

You might also like