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

Tutorial 3 Flow of Control (Selection)

This document discusses flow of control and selection statements in Java programming. It provides examples of if/else statements to determine conditions such as whether numbers are equal, strings are equal, numbers are positive or negative, and it is a leap year. It also includes examples with errors to correct and outputs for different conditions. The document aims to help students learn how to use if/else and switch statements to evaluate conditions and execute code blocks accordingly.

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)
96 views

Tutorial 3 Flow of Control (Selection)

This document discusses flow of control and selection statements in Java programming. It provides examples of if/else statements to determine conditions such as whether numbers are equal, strings are equal, numbers are positive or negative, and it is a leap year. It also includes examples with errors to correct and outputs for different conditions. The document aims to help students learn how to use if/else and switch statements to evaluate conditions and execute code blocks accordingly.

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