Search for notes by fellow students, in your own course and all over the country.

Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.

My Basket

You have nothing in your shopping cart yet.

Title: programming
Description: this notes is for degree students

Document Preview

Extracts from the notes are below, to see the PDF you'll receive please use the links above


IS142 LAB WORKSHEET FOR WEEK 5

Java Programming Tutorial
1
...
1 Exercises on Conditional (Decision)
Exercise 1
...

Hints:
public class CheckPassFail { // saved as "CheckPassFail
...
out
...
) {
System
...
println(
...
out
...
);
}
}
}

Exercise 1
...

Hints: n is an even number if (n % 2) is 0
...
java"
public static void main(String[] args) {
int number = 49;
// set the value of number here!
System
...
println("The number is " + number);
if (
...
out
...
);
} else {
System
...
println(
...
3a: PrintNumberInWord (nested-if, switch-case): Write a program
called PrintNumberInWord which prints "ONE", "TWO",
...
, 9, or other, respectively
...

Hints:
public class PrintNumberInWord {
// saved as "PrintNumberInWord
...
out
...
) {

1

IS142 LAB WORKSHEET FOR WEEK 5

...
) {

...

} else {

...
out
...


...

default: System
...
println("OTHER");
}
}
}

Exercise 1
...
“Saturday” if the int variable "day" is 0, 1,
...
Otherwise, it shall print
“Not a valid day”
...
2 Exercises on Loop (Iteration)
Exercise 1
...
1a SumAndAverage (Loop): Write a program called SumAndAverage to
produce the sum of 1, 2, 3,
...
g
...
Also compute and display the
average
...
5

Hints:
public class SumAndAverage {
// saved as "SumAndAverage
...
e
...
e
...
Beware that int/int produces int
...

// Print sum and average
...

}
}

Exercise 1
...
1b TRY:
Modify the program to use a "while-do" loop instead of "for" loop
...
2
...


Modify the program to use a "do-while" loop
...


What is the difference between "for" and "while-do" loops? What is the difference
between "while-do" and "do-while" loops?

1
...
3
...

# # # # #
# # # # #
# # # # #
# # # # #
# # # # #

Your program should use only two output statements, one EACH of the followings:
System
...
print("# ");
System
...
println();

// print # and a space, without newline
// print a newline

Hints:
public class SquareBoard {
// saved as "SquareBoard
...
) {
for (int col = 1;
...

}

...
Exercises on Keyboard and File Input
Exercise 2
...
The output shall look
like (the inputs are shown in bold):
Enter an integer: 12
Enter a floating point number: 33
...
44 is 45
...
util
...
in)
Scanner in = new Scanner(System
...
out
...
nextInt();
// use nextInt() to read int
System
...
print("Enter a floating point number: ");
num2 = in
...
out
...
next();
// use next() to read String
// Display

...
close();
}
}

Exercise 2
...
txt", and produce the following
output:
The integer read is 12
The floating point number read is 33
...
44 is 45
...
txt" (in Eclipse, right-click on the "project" ⇒ "New" ⇒
"File") with the following contents:
12
33
...
util
...
io
...
io
...
txt"));
num1 = in
...
nextDouble();
// use nextDouble() to read double
name = in
...

in
...
3:

CircleComputation (User

Input): Write

a

program

called CircleComputation, which prompts user for a radius (of double) and compute
the area and perimeter of a circle
...
2
The area is 4
...
5398223686155035

Hints: π is kept in a constant called Math
...


5


Title: programming
Description: this notes is for degree students