5 Problems for Assignment 5 - Java Programming | COP 2250, Assignments of Javascript programming

Material Type: Assignment; Class: Java Programming; Subject: Computer Programming; University: Florida International University; Term: Unknown 1989;

Typology: Assignments

Pre 2010

Uploaded on 09/17/2009

koofers-user-2o9
koofers-user-2o9 🇺🇸

4.5

(2)

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
COP2250 – ASSIGNMENT 5
Due Tuesday, April 15th
Instructions:
A signed statement stating that you have adhered to the collaboration policy for this class and that
what you are presenting is your own work.
If you have received help from any source other than your class notes or textbook, please cite the
source at the appropriate place. This includes tutorships.
The assignment should be typed and a stapled hardcopy of the same has to be submitted at the
beginning of the class.
For programming assignments, submit a hardcopy of the pseudo code, code and the printout of the
output.
The code should contain the following header:
/**
* Author: xyz
* Description: What the program is expected to do.
* Additional information about variables, parameters, etc
*/
Problems:
1. What is the output of this code sequence?
int s = 0;
int [ ] a = { 12, 48, 65 };
for ( int i = 0; i < a.length; i++ )
s += a[i];
System.out.println( “s = ” + s );
[10 points]
2. What is the output of this code sequence?
int [ ] a = { 12, 48, 65, 23 };
int temp = a[1];
a[1] = a[3];
a[3] = temp;
for ( int i = 0; i < a.length; i++ )
System.out.println( a[i] + “ ” );
[10 points]
pf2

Partial preview of the text

Download 5 Problems for Assignment 5 - Java Programming | COP 2250 and more Assignments Javascript programming in PDF only on Docsity!

COP2250 – ASSIGNMENT 5

Due Tuesday, April 15th

Instructions:

  • A signed statement stating that you have adhered to the collaboration policy for this class and that what you are presenting is your own work.
  • If you have received help from any source other than your class notes or textbook, please cite the source at the appropriate place. This includes tutorships.
  • The assignment should be typed and a stapled hardcopy of the same has to be submitted at the beginning of the class.
  • For programming assignments, submit a hardcopy of the pseudo code, code and the printout of the output.
  • The code should contain the following header: /** * Author: xyz * Description: What the program is expected to do. * Additional information about variables, parameters, etc */

Problems:

  1. What is the output of this code sequence?

int s = 0; int [ ] a = { 12, 48, 65 };

for ( int i = 0; i < a.length; i++ ) s += a[i];

System.out.println( “s = ” + s ); [10 points]

  1. What is the output of this code sequence?

int [ ] a = { 12, 48, 65, 23 }; int temp = a[1]; a[1] = a[3]; a[3] = temp;

for ( int i = 0; i < a.length; i++ ) System.out.println( a[i] + “ ” ); [10 points]

  1. What is the output of this code sequence?

String [ ][ ] cities = {{ “New York”, “LA”, “San Francisco”, “Chicago” }, { “Munich”, “Stuttgart”, “Berlin”, “Bonn” }, { “Paris”, “Ajaccio”, “Lyon” }, { “Montreal”, “Ottawa”, “Vancouver” } };

for ( int i = 0; i < cities.length; i++ ) { for ( int j = 0; j < cities[i].length; j++ ) { if ( cities[i][j].length() == 6 ) System.out.println( cities[i][j] ); [10 points]

  1. Fill in the code: This method returns the number of elements in an array passed as a parameter that are multiples of 7.

public int foo( int [ ] a) { // your code goes here } [20 points]

  1. Write an array-returning method that takes a two-dimensional array of chars as a parameter and returns a single-dimensional array of Strings as follows: The array returned should have a number of elements equal to the number of rows in the parameter array; every element of the array returned should be the concatenation of all the column elements of the corresponding row in the parameter array. Include code to test your method. [25 points]