


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: Introduction to Programming; Subject: COMPUTER SCIENCE; University: University of North Carolina - Chapel Hill; Term: Unknown 1989;
Typology: Assignments
1 / 4
This page cannot be seen from the preview
Don't miss anything!



Section 1: Short answer a. What is a class? An object? b. What is an array in Java? c. What is overloading? d. What is a constructor method? Section 2
Section 3 3.1 What does this method return when first <= last? What does this method return when first >= last? public static int mystery(int first, int last) { if (first > last) return 0; else if (first == last) return first; else return first +last; } when first<=last, if first == last, return first if first < last, return first+last when first>=last, if first ==last, return first if first > last, return 0 3.2. a) Declare and create an array of int type with length 100 and initialize the elements with their respective indices in the array. e.g., the value of the first element is 0, the value of the second element is 1… int[] a = new int[100]; for(int i=0; i<100; i++) a[i] = i; b) Compute the sum of the elements of the array and output the sum. int sum = 0; for( int i =0; i < 100; i++) sum += a[i]; System.out.println(sum);
Output: 3 6 5