Week11Chap7-II

Week11Chap7-II - Chapter 7 Arrays - Lecture V Janaka...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Janaka Balasooriya CSE 110, Arizona State University Chapter 7 Arrays - Lecture V
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Janaka Balasooriya CSE 110, Arizona State University Arrays as Method Parameters: Homework Solutions • We can pass arrays as method parameters. Syntax: methodName(arrayType . .. arrayReferenceName) Eg; public int addArray(int . .. a) Alternative Syntax – Old versions of Java methodName(arrayType[] arrayReferenceName) Eg; public int addArray(int[] a)
Background image of page 2
Janaka Balasooriya CSE 110, Arizona State University Arrays as Method Parameters public class Sum { public int add(int x, int y) { return (x + y); } public int addArray(int . .. a) { int total =0; for(int i =0 ; i<a.length ; i++) total += a[i]; return total; } } public class addNumbers { public static void main(String [] args) { int x =9, y = 8; int[] b = { 1, 2, 3, 4, 5}; Sum s1 = new Sum(); System.out.println( s1.add(x,y)); System.out.println(s1.addArray(b)); } }
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Janaka Balasooriya CSE 110, Arizona State University Homework: Not for Grading Problem: Design and implement the class “gradeCalculation” that determine a) Highest score b) Lowest score c) Class average
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 9

Week11Chap7-II - Chapter 7 Arrays - Lecture V Janaka...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online