0

I'm using a 2d array and am having to find the find the furthest two numbers apart and print both of them numbers. The text file I'm reading from has numbers from 0 to 194. Here is the code that I have so far. Any help with be greatly appreciated.

import java.util.*;
import java.util.Scanner.*;
import java.util.ArrayList.*;
import java.io.*;
import java.io.FileNotFoundException;

public class Cities extends Object
{

 Scanner in = new Scanner(System.in);
 
 private int  value;
 private int[][] distance = new int[4][4];
 private String file;
 private int c;
 private int r;
 private int row;
 private int column;
 private String cities[];
 public Cities(String file)
 {
  super();
  this.file=file;
  
 }
 
 	
    private void getFile()
    {
      try
       {
        in = new Scanner(new File(file));
       }
      
        catch(FileNotFoundException ex)
        {
         System.out.println(ex.getMessage());
  
        }
     }         





  
   private void fillArray()
   {
     
    
      for(int r = 0; r<4; r++)
      {         
       
       for(int c = 0; c<this.distance[r].length; c++)
       {
        
        this.distance[r][c] = in.nextInt();
         
       
       }
      }
      
   }
     public void distanceFile()
     {
      
      
       getFile();
	   fillArray();    
       findExtreme(value);     
     }
     public void displayFarthestPair()
     {
      

     }
    private int findExtreme(int indexToStart)
    {
        int value = indexToStart;
        int numberBestSoFar = this.distance[r][c];
       for(int r = 0; r<4; r++)
       { 
        for(int i = 0; i<this.distance.length; i++)
        {
         int currentDistance = this.distance[r][c];
         
         if(currentDistance>numberBestSoFar)
         {
          value = i;
          System.out.println(distance[r][c]);
         
         }
         if(currentDistance<0)
         {
         
         }
        }
       }        return value;
     }
    
    public static void main(String[] args)
    {
     Scanner in = new Scanner(System.in);
     System.out.println("Enter file name");
     String file = in.next();
     Cities city = new Cities(file);
     city.distanceFile();
    }
}
1
Contributor
1
Reply
2
Views
7 Years
Discussion Span
Last Post by helpmepassclass
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.