Sie sind auf Seite 1von 7

CSC 201

Lecture - 10
Agenda
• Review for Midterm
• Practice the Java methods and parameter
passing in Java.
• How to pass arrays as parameters in
Java.
Midterm review
1) Questions on what is the output of the following part of
code? Understanding of various loop constructs may
be involved. Please refer quiz tests conducted in class.
2) Understanding arrays, writing simple programs using
arrays. Please practice and understand arrays we did
in our lab sessions and our class notes.
3) Refer to the questions behind the chapters in our
textbook.
4) Practice writing methods and passing parameters.
(Very simple parameter passing will be covered)
• All material from (Data types to Static methods
included) must be reviewed for midterm.
• There will be 3 more homework and 4 more
quizzes in our remaining semester.
• There will be a final project instead of a final
examination. You will be given 4 weeks to complete
the project.
• The above schedule may be subject to change but
this is my tentative plan.
Arrays as Parameters
Class sample_array{
public static void myarray(int[] b)
{
b[0] = 7;
b[1] = 8;
b[2] = 9;
//return b;
}
public static void main(String[] args)
{

int[] a = {1, 2, 3};


myarray(a);
System.out.println(a[0]+" "+a[1]+" "+a[2]);

}
}
Integer as parameter
Class sample_integer {
public static void pass_integer(int num)
{
System.out.println("I am in method pass_integer");
num = 5;
System.out.println("Value of num is:"+num);

}
public static void main(String[] args)
{

int a;
a = 2;
pass_integer(a);
System.out.println("Value of a after we return from method is:"+a);

}
}
• Try passing other primitive data types as
parameter.

Das könnte Ihnen auch gefallen