public class MinDif {
public static void main(String[] args) {
EasyReader keyboard = new EasyReader();
EasyWriter screen = new EasyWriter();
//Create an array to the length of the specified entry
int numItems=keyboard.readInt("Enter the length of the array: ");
String[] myArray = new String[numItems];
// Read in the contents of the array
for (int i=0; i<numItems; i++)
myArray[i]=keyboard.readString("Enter number "+(i+1)+" (index"+i+") : ");
// Set a vairable and test it
int dMin = 0;
int i,j;
for(i=0; i< numItems; i++)
{
for(j=i+1; j< numItems;j++)
{
dMin = Math.min(dMin,( myArray[i]-myArray[j] ));
}
}
System.out.println(dMin);
}
}
I need to find the minimum difference between two adjacent elements within an array. This is the code i have so far. When compiling the program i get the error message:
bad operand types for binary operator '-'
and it points at the '-' used in (myArray-myArray[j])
Cheers