

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: Quiz; Class: Computer Programming I; Subject: Computer Science; University: Pace University-New York; Term: Unknown 1989;
Typology: Quizzes
1 / 2
This page cannot be seen from the preview
Don't miss anything!


November 3, 2005
Name: _____________________________
public class Test1 { public static void main(String[] args) { int x = 0; if (x == 0) { int x = 1; System.out.println(x); } } }
public class Test2 { public static void main(String[] args) { int x = 1; switch (x) { case 0: System.out.println(x); case 1: System.out.println(x); case 2: System.out.println(x); default: System.out.println(x); } } }
public class Test3 { public static void main(String[] args) { if (args.length == 0) System.exit(-1); int left = 0, right = args.length – 1; while (left < right) { String temp = args[left];
args[left] = args[right]; args[right] = temp; left++; right--; } for (int i = 0; i < args.length; i++) System.out.print(args[i] + " "); } }
public class Test4 { public static void main(String[] args) { int[][] a2 = new int[4][4]; for (int i = 0; i < a2.length; i++) for (int j = 0; j < a2[0].length; j++) a2[i][j] = i + j; int[] a1 = new int[a2[0].length]; for (int i = 0; i < a2[0].length; i++) { a1[i] = 0; for (int j = 0; j < a2.length; j++) a1[i] = a1[i] + a2[j][i]; } for (int i = 0; i < a1.length; i++) System.out.print(a1[i] + " "); } }