Font size
WorksheetsComprog - (Predefined Methods) November 8, 2022
Total questions: 27
Worksheet time: 14mins
Methods that are already written and provided by Java.
Predefined Methods
User-defined Methods
Prewritten Methods
Preprogrammed methods
Which of the following is NOT true about methods?
They are also called modules
It is used to divide complicated programs into manageable pieces
It enhances program's readability
They are ideal for shorter programs.
Predefined methods in Java are organized as a collection of classes known as ________.
Method libraries
Class libraries
Package Libraries
Module
What package contains the math class?
java.util
java.io
java.lang
java.sql
It is the data type of the value returned by the method.
method name
argument
parameter
method type
It returns the absolute value of z.
absolute(z)
abs(z)
ab(z)
(z)abs
It returns the larger of a and b.
large(a, b)
big(a, b)
min(a, b)
max(a, b)
Which of the following statements is INCORRECT?
Math.abs(-100);
Math.max(2, 4);
Math.sin(10);
Math.pow(2, 3);
List all arguments/actual parameters that exist in this program segment:-
double point, String student
point, student
name, mark
name[i], mark[i]
List all formal parameters that exist in this program segment:-
double point, String student
i, mark
name, mark
name[i], mark[i]
Identify the error that exist in this program segment:-
An array data type cannot be use as argument.
The argument was not in the right sequence with the parameter.
The variable name in parameter not as same with the argument.
Program consist 0 error.
Identify the object that used to call a method.
Status
name[i], mark[i]
mtd
void
Fix the error by replacing with the correct java statement.
void Status(String student, double point)
void Status ( name[i], mark[i] )
int Status(String student, double point)
void Status ( String name[i], double mark[i] )
Create a method name Bonus that will read a basic payment and an hour variable as parameter to calculate an extra salary.
Identify the error that exist in this method program:-
Wrong use of return method type
variable extra was unknown.
doble is not one of the data type
A wrong use of hour data type.
Identify the error that exist in this method program:-
Wrong use of return method type
variable extra was unknown.
doble is not one of the data type
A wrong use of hour data type.
Identify the error that exist in this method program:-
Wrong use of return method type
variable extra was unknown.
All of the parameters data type was not stated.
missing { } in if statement.
What is the Output if the argument is (5500.00, 12.5)
There will be no output.
20, 625.00
27,500.00
34,375.00
What is the Output if the argument is (1300.00, 15.0)
9,750.00
7,800.00
There will be no output.
5,850.00
What is the Output if the argument is (13.0, 2789.00)
14,502.00
10,877.00
18,128.50
There will be no output.
What is the Output if the argument is (1000.00, 14.30)
4,290.00
5,720.00
7,150.00
There will be no output.
Identify types of error that exist in this method program:-
Logic error
runtime error
syntax error
exception
Why method is important?
Break program into a small program and easy to debug.
Easier to read and understand aspecially when involving with a big program.
More practical when we need to reuse the code.
Can store more similar values in a single variable.
What is the order of parameters in a call to the method one?
int, double, char, String
int, double, String, char
int, char, String, double
int, char, double, String
Which of the following Java statements is correct?
System.out.print (one (5, 'r', 1.5, "Hi"));
System.out.print (one (5, 1.5, 'r', "Hi"));
System.out.print (one ("Hi", 'r', 1.5, 5));
System.out.print (one ('r', 5, 1.5, "Hi"));
Which of the following Java statements is correct?
System.out.print (two (t, w, o));
System.out.print (two ("t", "w", "o"));
System.out.print (two (4.0, 4.0, 4.0));
System.out.print (two ('4', '4', '4'));
Which of the following Java statements is correct?
System.out.print (three (17, "Ana", 'f'));
System.out.print (three ("Ana", 'f', 17));
System.out.print (three ("Ana", 17, 'f'));
System.out.print (three ('f', 17, "Ana"));
