Lect 3.2 Scheme_examples - public class Imperativecfw just...

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

View Full Document Right Arrow Icon
public class Imperative { // just a program name static int area = 0 ; // global height=4 static int result = 0 ; public static void calAreaProc(int length, int width) { area = length * width ; length =3 width=2 } public static void sumProc(int val1, int val2) { result = val1 + val2 ; } public static void displayResultProc(String str) { System.out.println(str + result) ; } ublic static void main(String[] rgs { public static void main(String[] args) { calAreaProc(2,3) ; sumProc(result, area * 2) ; // side effect calAreaProc(4,3) ; umProc esult area * 2) ; sumProc(result, area 2) ; calAreaProc(4,2) ; sumProc(result, area * 2) ; displayResultProc("The total surface area of cubiod is "); } } 57
Background image of page 1

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

View Full DocumentRight Arrow Icon
public class Cubiod { int length, width, height = 0 ; height=4 public Cubiod (int length, int width, int height) { this.length = length ; this.width = width ; length =3 width=2 this.height = height ; } public int getArea (int l, int b) { return l * b ; } public int getTotalSurfaceArea(){ return 2 * (getArea(length ,width) +
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/08/2010 for the course SCE CSC301 taught by Professor Mr.leong during the Fall '10 term at Nanyang Technological University.

Page1 / 5

Lect 3.2 Scheme_examples - public class Imperativecfw just...

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

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