Integers in the range 100500 d the boolean condition

This preview shows page 4 - 8 out of 13 pages.

Integers in the range 100–500d)The boolean condition can never be true
1.7Assume the following class:public class Circle{private double radius;public Circle(double radius){this.radius = radius;}}The following statement in themain()means:Circle[] x = new Circle[10];
1.8What is the output of the following code?public class Test{public static void main(String[] args){int[] a = {1, 2};swap(a[0], a[1]);System.out.println(a[0] + "--" + a[1]);}public static void swap(int n1, int n2){int temp = n1;n1 = n2;n2 = temp;}}
1.9Assume the following code. Which statement is nottrue?public class Sphere{private double radius;publicdouble x;private double y;private double z;}
COMP 248 – AA S2012Final ExamPage 5 of 13
Question 3(8pts) What is the output of the following program segment?int[] myArray = {4, 0, 9, 2, 6, 3, 5, 7, 8, 2};int left, right;int last = myArray.length-1;for (int i = 0; i < myArray.length; i++)System.out.print(myArray[i]);for (left = 0, right = last-1; left < right; ){while (myArray[left] > myArray[last])left++;while (myArray[right] < myArray[last])right--;System.out.print("\n" + left + " " + right + "\n");int temp = myArray[left];myArray[left] = myArray[right];myArray[right]= temp;for (int i = 0; i<myArray.length; i++)System.out.print(myArray[i]);}
COMP 248 – AA S2012Final ExamPage 6 of 13Answer:
COMP 248 – AA S2012Final ExamPage 7 of 13Question 4 (13pts)A- (10pts)Write a public static method calledproduct_nthat takes an integernas parameter andreturns the product of the n first integers.For example, ifnis 4, your method should compute andreturn 24 (because 1×2×3×4= 24).Note: If the value ofnis zero or is negative, your method should return zero.Answer:B-(3pts)Assume that you are in the same class as the method declared in partAabove, and you can calland use the methodproduct_nthat you declared above.Write the appropriate instructions to call yourmethod and display “YES” if the product of 1 to 50 is greater than 1000; and display “NO” otherwise.

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 13 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Spring
Professor
T.B.A
Tags
Object Oriented Programming, Subroutine, Mutator method

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture