


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
The solutions and discussions for exam 2 of the cos 126 fall 2006 course. It includes java code snippets, explanations of algorithms, and discussions on the limitations of program verification.
Typology: Exams
1 / 4
This page cannot be seen from the preview
Don't miss anything!



public class Palindrome { public static boolean isPunc(char c){ if ((c==' ')|| (c==',')||(c =='.')||(c==':')|| (c==';')||(c=='!')||(c=='?')) return true; else return false; } public static void main(String[] args) { String s = args[0].toLowerCase(); boolean pal = true; for (int i=0, j=s.length()-1; i < j; i++, j--) { while (isPunc(s.charAt(i))) i++; while (isPunc(s.charAt(j))) j--; if (s.charAt(i) != s.charAt(j)) pal = false; } System.out.println(pal); } }
public class Client { public static void main (String[] args) { int N = Integer.parseInt(args[0]); Interval[] intervals = new Interval[N]; for (int i = 0; i < N; i++) { intervals[i] = new Interval(StdIn.readDouble(), StdIn.readDouble()); } for (int i = 0; i < N; i++){ for (int j = i + 1; j < N; j++) { if (intervals[i].intersects(intervals[j])) System.out.println(intervals[i] + " intersects " + intervals[j]); } } } }