Check10C - for(String index1 list for(String index2 list...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.io.*; import java.util.*; i public class Check10C { @SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { PrintStream out = System.out; out.print("Enter the filename "); FileInputStream fis = new FileInputStream((new Scanner(System.in)).nextLine()); ObjectInputStream input = new ObjectInputStream(fis); Object buffer = input.readObject(); List<String> list = null; if (buffer instanceof ArrayList) { list = (ArrayList<String>)buffer;//(ArrayList<String>)input.readObject(); } input.close(); //D:\Users\DJ\Downloads\York\Fall 2010\Programming\1020\Projects\CSE1020\src\lab10data.dat int lengthChange = Integer.MAX_VALUE, first = 0, second = 0, i = 0;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: for (String index1 : list) { for (String index2 : list) { if (!index1.equals(index2)) { int delta = Math.abs(index1.length() - index2.length()); lengthChange = (delta <= lengthChange) ? delta : lengthChange; } } } for (String index1 : list) { int j = 0; for (String index2 : list) { if (!index1.equals(index2)) { int delta = Math.abs(index1.length() - index2.length()); if (lengthChange == delta && first == 0 && second == 0) { first = i; second = j; } } j++; } i++; } out.println("The closest two are " + lengthChange + " apart in length."); out.printf("Their indices are %d,%d.%n", first, second); } }...
View Full Document

{[ snackBarMessage ]}

Page1 / 2

Check10C - for(String index1 list for(String index2 list...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online