Tutorial 01-Answers
Tutorial 01-Answers
Question 01
Input two numbers from the key board and then find a largest number among two numbers
using a java method.
Note: You can use ‘built-in method’ for that.
import java.util.Scanner;
Result:
Number one: 9
Number two:5
The largest number is =9
1
Object Oriented System Design - ICT 325
Question 02
Write a program with a method named getAvg that accepts two integers as an argument and
return its average. You can get two integer numbers from the key board and print the results
by calling this method from main().
import java.util.Scanner;
Result:
Enter first number: 5
Enter second number: 8
Average: 6
2
Object Oriented System Design - ICT 325
Question 03
Create a method to find out given number is odd or even. You can define a number inside the
program.
class Ex03 {
Result:
Number is even
Question 04
“A method which calls itself is called recursive method.” Use a recursive method to get a
factorial (factorial of 4 is 4x3x2x1 = 24) of a given number.
class Ex04 {
Result:
Factorial of 4 is 24
3
Object Oriented System Design - ICT 325