Okay i posted a question like a day ago and didn't get no response, I did however figure out the problem. The problem I am having now with is the fact that it finds the numbers that i want it to but it also adds a zero which is in the array even though i tell the array not to take that into consideration. If there was a way to give you the text file I would be more than willing but i don't know how too since i am new here but the numbers start from zero to 194 because they are distances between cities. I'm not looking for an answer just a direction to go in. I have checked the API for java and that is no help. I am hoping that someone can help, it will 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 valueOne;
private int valueTwo;
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();
displayFarthestDistance();
displayClosestDistance();
}
private int displayFarthestDistance()
{
int maxValue = 0;
int minValue = 9999;
int numberBestSoFar = this.distance[r][c];
for(int r = 0; r<4; r++)
{
for(int c = 0; c<this.distance.length; c++)
{
int currentDistance = this.distance[r][c];
if(currentDistance>maxValue)
{
maxValue = currentDistance;
}
if(currentDistance<minValue && currentDistance != 0)
{
minValue = currentDistance;
}
}
}
System.out.println(maxValue);
System.out.println(minValue);
return value;
}
private int displayClosestDistance()
{ int value1 = 65;
int value2 =45;
int numberBestSoFar = this.distance[r][c];
for(int r = 0; r<4; r++)
{
for(int c = 0; c<this.distance.length; c++)
{
int currentDistance = this.distance[r][c];
if(currentDistance<value1)
{
value1 = currentDistance;
}
if(currentDistance>value2 && currentDistance <= 65)
{
if(currentDistance !=0)
{
value2 = currentDistance;
}
}
}
}
System.out.println(value1);
System.out.println(value2);
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();
}
}