Gauss Seidel Method - java

I wrote a Gauss-Seidel method to calculate the unknown x values of a matrix A. Another methods online seemed to check first if the determinant contains non-zeroes, but other algorithms, including my prof's notes, don't have the verification check.
So I just followed the algorithm that my professor gave in class for now, and I think that the first xNew is correct, because I verified it on my calculator, but my other x values are not updating, can anyone see why?
public static void gaussSeidel(double[][] A, double[] b){
int count = 0;
boolean stop = false;
do{
double[] xNew = new double[b.length]; // x2 = 0, x3 = 0,
double[] xOld = new double[b.length];
for(int i = 0; i < A.length; i++){
double sum = 0.0;
double sum1 = 0.0;
for(int j = 0; j < A.length; j++){
if( j != i)
sum += (A[i][j]*xOld[j]);
sum1 += (A[i][j]*xNew[j]);
}
xNew[i] = (b[i] - sum - sum1)*(1/A[i][i]);
System.out.println("X_" + (i+1) + ": " + xNew[i]);
System.out.println("Error is: " + Math.abs((xNew[i] - xOld[i])));
System.out.println("");
count++;
if(Math.abs(xNew[i] - xOld[i]) > EPSILON){
xNew[i] = xOld[i];
}
else{
stop = true;}
}
}while( !stop && count <= MAX_ITERATIONS);
}
My matrix:
double[][] a = {{12,-2,1,0,0,0,0,0,0,0,0},
{-2,12,2,1,0,0,0,0,0,0,0}, {1,-2,12,-2,1,0,0,0,0,0,0}, {0,1,-2,12,-2,1,0,0,0,0,0},
{0,0,1,-2,12,2,1,0,0,0,0}, {0,0,0,1,-2,12,-2,1,0,0,0},
{0,0,0,0,1,-2,12,-2,1,0,0},{0,0,0,0,0,1,-2,12,-2,1,0},
{0,0,0,0,0,0,1,-2,12,-2,0},{0,0,0,0,0,0,0,1,-2,12,0}};
My b values:
double[] b = {13.97, 5.93, -6.02, 8.32, -23.75, 28.45, -8.9, -10.5, 10.34, -38.74};

Every time you loop, you are creating the following arrays again and again:
double[] xNew = new double[b.length]; // x2 = 0, x3 = 0,
double[] xOld = new double[b.length];
Surely, you are loosing the values that you have computed in the previous loop. I would think that you would only need to create these once, so outside of your loop as follows:
public static void gaussSeidel(double[][] A, double[] b){
int count = 0;
boolean stop = false;
double[] xNew = new double[b.length]; // x2 = 0, x3 = 0,
double[] xOld = new double[b.length];
do{
for(int i = 0; i < A.length; i++){
double sum = 0.0;
double sum1 = 0.0;
for(int j = 0; j < A.length; j++){
if( j != i)
sum += (A[i][j]*xOld[j]);
sum1 += (A[i][j]*xNew[j]);
}
xNew[i] = (b[i] - sum - sum1)*(1/A[i][i]);
System.out.println("X_" + (i+1) + ": " + xNew[i]);
System.out.println("Error is: " + Math.abs((xNew[i] - xOld[i])));
System.out.println("");
count++;
if(Math.abs(xNew[i] - xOld[i]) > EPSILON){
xNew[i] = xOld[i];
}
else{
stop = true;}
}
}while( !stop && count <= MAX_ITERATIONS);
}

Related

Bruteforce and Conquer and Divide not giving same distance answer for Closest Pair of Points

I created a program that generates a user inputted number of pairs of points. It then goes through a bruteforce and divide and conquer methods to find the closest pair of points. The bruteforce method works perfectly. The divide and conquer method on the other hand gives me an output but it is different than the brute force distance almost 90% of the time. I can't seem to figure out why it is like this in my code. NOTE: Some of the comments in the functions are from my teacher. Also, the closest_pair function along with rec_cl_pair have been given to me by my teacher where I must use them but had to adjust to my code (they were pseudo code for most part).
My code is:
import java.util.*;
import static java.lang.Math.min;
public class ClosestPair{
private Double x;
private Double y;
private static Double minDist = Double.POSITIVE_INFINITY;
private static ClosestPair closestPair1 = new ClosestPair(0.0,0.0);
private static ClosestPair closestPair2 = new ClosestPair(0.0,0.0);
public ClosestPair(Double x, Double y){
this.x = x;
this.y = y;
}
public static void main(String[] args) {
Double rangeMin = 0.0;
Double rangeMax = 1000.0;
Random r = new Random();
Scanner scan = new Scanner(System.in);
System.out.print("\nEnter the number of two dimensional arrays: ");
int dim = scan.nextInt();
ClosestPair[] pair = new ClosestPair[dim];
ClosestPair[] pairCopy = new ClosestPair[dim];
for(int i = 0; i < dim; i++){
Double xVal = rangeMin + (rangeMax - rangeMin) * r.nextDouble();
Double yVal = rangeMin + (rangeMax - rangeMin) * r.nextDouble();
pair[i] = new ClosestPair(xVal,yVal);
//System.out.print(pair[i].x + ", " + pair[i].y + "\n");
}
/*
for(int j = 0; j < pair.length; j++){
System.out.print(pair[j].x + ", " + pair[j].y + "\n");
}
*/
pairCopy = pair;
pair = mergeSort(pair);
/*
System.out.print("\n\n\n");
for(int j = 0; j < pair.length; j++){
System.out.print(pair[j].x + ", " + pair[j].y + "\n");
}
*/
//BRUTE FORCE PRINT STATEMENTS
long startTime = System.nanoTime();
bruteForce(pair);
long endTime = System.nanoTime();
long timeSpent = endTime - startTime;
System.out.print("\nMin Distance = " + minDist);
System.out.print("\n(x1,y1) = " + closestPair1.x + ", " + closestPair1.y);
System.out.print("\n(x2,y2) = " + closestPair2.x + ", " + closestPair2.y);
System.out.print("\nTime: " + timeSpent + "\n\n");
minDist = 0.0;
//CONQUER DIVIDE PRINT STATEMENTS
startTime = System.nanoTime();
minDist = closest_pair(pairCopy);
endTime = System.nanoTime();
timeSpent = endTime - startTime;
System.out.print("Min Distance = " + minDist);
System.out.print("\nTime: " + timeSpent);
scan.close();
}
private static void bruteForce(ClosestPair[] pair) {
for(int i = 1; i < pair.length - 1; i++){
for(int j = i + 1; j < pair.length; j++){
ClosestPair p = new ClosestPair(pair[i].x,pair[i].y);
//System.out.print("\np:" + pair[i].x + ", " + pair[i].y);
ClosestPair q = new ClosestPair(pair[j].x,pair[j].y);
//System.out.print("\nq: " + pair[j].x + ", " + pair[j].y);
if(getDistance(p, q) < minDist){
minDist = getDistance(p, q);
closestPair1.x = p.x;
closestPair1.y = p.y;
closestPair2.x = q.x;
closestPair2.y = q.y;
}
}
}
}
private static Double getDistance(ClosestPair p1, ClosestPair p2) {
double xdist = p2.x - p1.x;
double ydist = p2.y - p1.y;
return Math.hypot(xdist, ydist);
}
static ClosestPair[] mergeSort(ClosestPair[] a) {
if (a.length > 1) {
int q = a.length/2;
ClosestPair[] leftArray = Arrays.copyOfRange(a, 0, q);
ClosestPair[] rightArray = Arrays.copyOfRange(a,q,a.length);
mergeSort(leftArray);
mergeSort(rightArray);
a = merge(a,leftArray,rightArray);
}
return a;
}
static ClosestPair[] merge(ClosestPair[] a, ClosestPair[] l, ClosestPair[] r) {
int totElem = l.length + r.length;
//int[] a = new int[totElem];
int i,li,ri;
i = li = ri = 0;
while ( i < totElem) {
if ((li < l.length) && (ri<r.length)) {
if (l[li].x < r[ri].x) {
a[i] = l[li];
i++;
li++;
}
else {
a[i] = r[ri];
i++;
ri++;
}
}
else {
if (li >= l.length) {
while (ri < r.length) {
a[i] = r[ri];
i++;
ri++;
}
}
if (ri >= r.length) {
while (li < l.length) {
a[i] = l[li];
li++;
i++;
}
}
}
}
return a;
}
//START OF CONQUER DIVIDE SECTOIN
static double closest_pair(ClosestPair[] p){
int n = p.length - 1;
p = mergeSortDC(p, 0, n); // sort all n points by x-coordinate
return rec_cl_pair(p, 0, n);
}
static double rec_cl_pair(ClosestPair[] p, int i, int j){ // finds closest pair between points in p[i..j]
// assumes input is sorted by x-coordinate
// at termination, input is sorted by y-coordinate
// i is the left index of the subarray, j is the right index
if (j - i < 3){ // at most 3 points in p[i..j]
p = mergeSortDC (p, i, j); // sort p[i..j] by y-coordinate
double delta = getDistance(p[i], p[i+1]);
if (j - i == 1) { // two points
minDist = delta;
return delta;
}
else{
double min1 = min(getDistance(p[i+1], p[i+2]), getDistance(p[i], p[i+2]));
minDist = min(delta,min1);
return minDist;
}
}
int m = (i + j)/2;
double line = p[m].x;
double deltaL = rec_cl_pair(p, i, m); // p[i..m] is sorted by y-coordinate
double deltaR = rec_cl_pair(p, m+1, j); // p[m+1..j] is sorted by y-coordinate
double delta = min(deltaL, deltaR);
p = mergeDC(p, i, m, j); // p[i..j] is now sorted by y-coordinate
// Of points in p[i..j], find points in vertical strip of width 2*delta,
// centered at line (middle of x-values), and store in array v
int t = 0;
ClosestPair[] v = new ClosestPair[j+1];
for(int k = i; k < j; k++){
if ((p[k].x > line - delta) && (p[k].x < line + delta)){
t = t + 1;
v[t] = p[k];
}
}
// Find closest pairs among points in array v. NOTE: Cool math shows
// there are at most 8 points in the strip at distance < delta. Thus,
// in the loops below, each point is compared to at most 7 other points.
for(int k = 1;k < t-1; k++){
for(int s = k+1; k < min(t,k+7); s++){ // inner loop iterates <= 7 times
delta = min(delta, getDistance(v[k],v[s]));
minDist = delta;
return delta;
}
}
return minDist;
}
private static ClosestPair[] mergeSortDC(ClosestPair[] p, int low, int high) {
// check if low is smaller then high, if not then the array is sorted
if (low < high) {
// Get the index of the element which is in the middle
int middle = low + (high - low) / 2;
// Sort the left side of the array
mergeSortDC(p, low, middle);
// Sort the right side of the array
mergeSortDC(p, middle + 1, high);
// Combine them both
p = mergeDC(p, low, middle, high);
}
return p;
}
private static ClosestPair[] mergeDC(ClosestPair[] p, int low, int middle, int high) {
ClosestPair[] helper = new ClosestPair[p.length];
// Copy both parts into the helper array
for (int i = low; i <= high; i++) {
helper[i] = p[i];
}
int i = low;
int j = middle + 1;
int k = low;
// Copy the smallest values from either the left or the right side back
// to the original array
while (i <= middle && j <= high) {
if (helper[i].x <= helper[j].x) {
p[k] = helper[i];
i++;
} else {
p[k] = helper[j];
j++;
}
k++;
}
// Copy the rest of the left side of the array into the target array
while (i <= middle) {
p[k] = helper[i];
k++;
i++;
}
return p;
}
}
An example of output is:
Enter the number of two dimensional arrays: 50
Min Distance = 19.014027210555614
(x1,y1) = 76.99595098629398, 600.1657767818473
(x2,y2) = 87.04091889578226, 616.3098732403395
Time: 3852815
Min Distance = 29.457199999686082
Time: 414081
The first min distance is the bruteforce result. The second is the divide and conquer result

Program to generate a matrix defined by user in java

guys!
First of all, I'm from Brazil, so sorry if I make some grammar error.
I'm having problems to solve an exercise in whitch I have to a program that generates a matix in java with user-informed dimensions. Then, it has to fill the matrix with values ​​which are also entered by the user. My code stops of running in my second for, passing by the columns. I get a ArrayIndexOutOfBoundException. Can you help me to see what I'm doing wrong?
import java.util.Scanner;
public class DiagonalsSum {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int[][] matrix;
int[] sizes = new int[2];
int diagonalsSum = 0, i, j, n, m;
for(i = 0; i < 2; i++){
n = i + 1;
System.out.println("Inform the " + n + " dimension of the matrix");
sizes[i] = s.nextInt();
}
matrix = new int[sizes[0]][sizes[1]];
for(i = 0; i < matriz.length; i++){
n = i + 1;
System.out.println(n);
for(j = 0; j < matrix[sizes[0]].length; j++){
m = j = 1;
System.out.println("Inform the value of " + n + "." + m +
" in the matrix:");
matrix[i][j] = s.nextInt();
}
}
s.close();
i = 0;
j = 0;
while(i < matrix.length && j < matrix[sizes[1]].length){
diagonalsSum += matrix[i][j];
i++;
j++;
}
i = 0;
j = (matrix[sizes[i]].length - 1);
while(i < matrix.length && j > 0){
diagonalsSum += matrix[i][j];
i++;
j--;
}
System.out.println("The sum of the primary and secondary diagonals is " + diagonalsSum);
}
Thanks in advance, guys!
Try this:
for(i = 0; i < matrix.length; i++){
matrix[i] = new int[sizes[1]];
n = i + 1;
System.out.println(n);
for(j = 0; j < matrix[sizes[0]].length; j++){
m = j = 1;
System.out.println("Inform the value of " + n + "." + m +
" in the matrix:");
matrix[i][j] = s.nextInt();
}
}
Java's an object-oriented language. You'll do better if you encapsulate the behavior you need in a proper Matrix class.
I think there are a couple of errors in here, but I'll address the one you've asked about.
I believe
for(j = 0; j < matrix[sizes[0]].length; j++)
will always result in going out of bounds because you've declared:
matrix = new int[sizes[0]][sizes[1]];
Note that Java has 0 based indexing, meaning that for any array, array[array.length] will be out of bounds. This type of access is effectively what your for loop is doing.
for(j = 0; j < matrix[sizes[0]-1].length; j++)
should fix the column loop issue.
guys!
I changed some things and it worked!
Thanks for all the help!
import java.util.Scanner;
public class DiagonalsSum {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int[][] matrix;
int[] sizes = new int[2];
int diagonalsSum = 0, i, j, n, m;
for(i = 0; i < 2; i++){
n = i + 1;
System.out.println("Inform the " + n + " dimension of the matrix");
sizes[i] = s.nextInt();
}
matrix = new int[sizes[0]][sizes[1]];
for(i = 0; i < sizes[0]; i++){
n = i + 1;
System.out.println(n);
for(j = 0; j < sizes[1]; j++){
m = j = 1;
System.out.println("Inform the value of " + n + "." + m +
" in the matrix:");
matrix[i][j] = s.nextInt();
}
}
s.close();
i = 0;
j = 0;
while(i < sizes[0] && j sizes[1]){
diagonalsSum += matrix[i][j];
i++;
j++;
}
i = 0;
j = (sizes[1] - 1);
while(i < sizes[0] && j > -1){
diagonalsSum += matrix[i][j];
i++;
j--;
}
System.out.println("The sum of the primary and secondary diagonals is " + diagonalsSum);
}

Memory Function Knapsack

Ok, I am having a problem with the Memory Function implementation of the Knapsack problem. My implementation if giving me the incorrect answer in Java but in C++ the same implementation is giving me the correct answer.
import java.io.*;
import java.util.*;
public class KnapsackMF {
public static void main(String args[]){
int wt;
int vl;
long start, end, runTime;
Scanner input = new Scanner(System.in);
int n, W;
System.out.println("Please enter the number of items: ");
n = input.nextInt();
System.out.println("Please enter the capacity of the knapsack: ");
W = input.nextInt();
int[][] V = new int[n+1][W+1];
int[] Wt = new int[n];
int[] Vl = new int[n];
for(int i = 0; i < n; i++){
System.out.println("Enter the weight and the value of item " + i + ": ");
wt = input.nextInt();
vl = input.nextInt();
Wt[i] = wt;
Vl[i] = vl;
}
for(int i = 0; i <= n; i++ ){
for(int j = 0; j <= W; j++){
if(j == 0 || i == 0){
V[i][j] = 0;
}
else{
V[i][j] = -1;
}
}
}
/*
for(int i= 0; i <= n; i++){
for(int j = 0; j <= W; j++){
System.out.print(V[i][j] + " ");
}
System.out.println();
}
*/
start = System.nanoTime();
System.out.println("The highest value is: " + MFKnapsack(n, W, V, Vl, Wt));
end = System.nanoTime();
runTime = (end - start);
System.out.println("Nanoseconds: " + runTime);
for(int i= 0; i <= n; i++){
for(int j = 0; j <= W; j++){
System.out.print(V[i][j] + " ");
}
System.out.println();
}
//system("PAUSE");
}
public static int MFKnapsack(int i, int j, int[][] V, int[] Vl, int[] Wt){
int value = 0;
if(V[i][j] < 0){
if(j < Wt[i-1]){
value = MFKnapsack(i-1, j, V, Vl, Wt);
}
else{
value = Math.max(MFKnapsack(i-1, j, V, Vl, Wt), Vl[i-1] + MFKnapsack(i-1, j-Wt[i-1], V, Vl, Wt));
}
}
V[i][j] = value;
return V[i][j];
}
}
The example I used is out of my book, the inputs should be:
4
5
2 12
1 10
3 20
2 15
The answer to this should be 37 but something is going on that I am not seeing and it is giving me 35.

Sorting an array and using binary search

I've already gotten this program to run and it almost gives me the answer I want. After running the whole program, it's supposed to print out the index of the key and what the key is equal too. I cannot for the life of me figure out how to get the index into the final message in the console. For example, if you have an array of {0,1,2,3,4,5,6,7,8,9} and your key is 0, it's supposed to return: list[0] = 0. I labeled the part I think where my problem lies with "(index???)"
import java.util.Scanner;
public class PartA {
public static void main(String[] args){
System.out.println("Please enter 10 double values:");
double [] array = inputArray();
selectionSort(array);
printArray(array);
System.out.println("Please enter a search key:");
Scanner input = new Scanner(System.in);
double key = input.nextDouble();
double x = binarySearch(array,key);
if (x != -1)
System.out.println("list[" + (index???) + "] = " + key);
else
System.out.println(key + " is not on the list");
}
public static double[] inputArray(){
Scanner array = new Scanner(System.in);
double [] list = new double[10];
for(int i = 0; i < list.length; i++){
array.hasNextDouble();
list[i] = array.nextDouble();
}
return list;
}
public static void selectionSort(double[] list){
double array[] = new double [list.length];
for(int i = 0; i < list.length; i++){
for(int j = 0; j < list.length; j++){
if (list[i] < list[j]){
double x = list[i];
list[i] = list[j];
list[j] = x;
}
}
}
}
public static void printArray(double[] list){
for (int i = 0; i < list.length; i++){
System.out.println("list[" + i + "] = " + list[i]);
}
System.out.println();
}
public static int binarySearch(double []list, double key){
int low = 0, high = list.length - 1;
while(high >= low){
int mid = (low + high)/2;
if(key < list[mid])
high = mid - 1;
else if(key == list[mid])
return mid;
else low = mid + 1;
}
return -1;
}
}
I also mentioned already in the comments of the Question the solution, but for the sake of completeness i post this answer.
public class Main {
public static void main(String[] args){
System.out.println("10 double values:");
double [] array = {0,1,2,3,4,5,6,7,8,9};
selectionSort(array);
printArray(array);
double key = 4;
System.out.println("Searched Key: " + key);
int idx = binarySearch(array,key); //use int instead of double
if (idx != -1)
//use the variable identifier to print the index
System.out.println("list[" + idx + "] = " + key);
else
System.out.println(key + " is not on the list");
}
public static void selectionSort(double[] list){
double array[] = new double [list.length];
for(int i = 0; i < list.length; i++){
for(int j = 0; j < list.length; j++){
if (list[i] < list[j]){
double x = list[i];
list[i] = list[j];
list[j] = x;
}
}
}
}
public static void printArray(double[] list){
for (int i = 0; i < list.length; i++){
System.out.println("list[" + i + "] = " + list[i]);
}
System.out.println();
}
public static int binarySearch(double []list, double key){
int low = 0, high = list.length - 1;
while(high >= low){
int mid = (low + high)/2;
if(key < list[mid])
high = mid - 1;
else if(key == list[mid])
return mid;
else low = mid + 1;
}
return -1;
}
}
Working example with Ideone:
http://ideone.com/WXrJPi
I think your code works perfect. You just have to replace (index???) with x and change the type of x from double to int so that is does not print the the value as a double value.
int x = binarySearch(array,key);
if (x != -1)
System.out.println("list[" + (x) + "] = " + key);
else
System.out.println(key + " is not on the list");
}
Output:
Please enter 10 double values:
0
1
2
3
4
5
6
7
8
9
list[0] = 0.0
list[1] = 1.0
list[2] = 2.0
list[3] = 3.0
list[4] = 4.0
list[5] = 5.0
list[6] = 6.0
list[7] = 7.0
list[8] = 8.0
list[9] = 9.0
Please enter a search key:
5
list[5] = 5.0

points of intersection by determinate not working

I have unfinished code to find the points of intersection of all lines that are perpendicular. So far I have this:
import java.util.Scanner;
public class CountSquares {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
int lines = scan.nextInt();
scan.nextLine();
double[][] lineMXYC = new double[4][lines]; // stores the slope, and x
// and y co-ordinates and c
// so the line can be
// represented as y = mx + c
double x1 = 0.0, x2 = 0.0, y1 = 0.0, y2 = 0.0;
double slope = 0.0;
for (int i = 0; i < lines; i++) {
String input = scan.nextLine();
String[] arrayOfInput = input.split(" ");
x1 = Integer.parseInt(arrayOfInput[0]);
y1 = Integer.parseInt(arrayOfInput[1]);
x2 = Integer.parseInt(arrayOfInput[2]);
y2 = Integer.parseInt(arrayOfInput[3]);
if (x1 == x2)
slope = Double.POSITIVE_INFINITY;
else
slope = (y2 - y1) / (x2 - x1);
lineMXYC[0][i] = slope;
lineMXYC[1][i] = x1;
lineMXYC[2][i] = y1;
lineMXYC[3][i] = y1 - (slope * x1);
}
for (int j = 0; j < lines - 1; j++) { //sorts the array by slopes
if (lineMXYC[0][j] > lineMXYC[0][j + 1]) {
double TEMP = lineMXYC[0][j + 1];
lineMXYC[0][j + 1] = lineMXYC[0][j];
lineMXYC[0][j] = TEMP;
}
}
double[] pointsOfIntersectionX = new double[(int) (lines * lines / 4) + 1]; //max number of points there can be
double[] pointsOfIntersectionY = new double[(int) (lines * lines / 4) + 1];
int count = 0;
for (int k = 0; k < lines; k++) {
for (int n = k; n < lines; n++) {
System.out.println(n + " " + k);
if (1 / lineMXYC[0][k] == -lineMXYC[0][n]) {
double m1 = lineMXYC[0][k];
double m2 = lineMXYC[0][n];
double c1 = lineMXYC[3][k];
double c2 = lineMXYC[3][n];
System.out.println("m1: "+m1);
System.out.println("m2: "+m2);
System.out.println("c1: "+c1);
System.out.println("c2: "+c2);
pointsOfIntersectionX[count] = (c1 - c2) / (m2 - m1); //determinate to find x co-ordinate
pointsOfIntersectionY[count] = (m2 * c1 - m1 * c2)
/ (m2 - m1);
System.out.println("The lines intersect at: ("
+ pointsOfIntersectionX[count] + ", "
+ pointsOfIntersectionY[count] + ")");
count++;
}
}
}
scan.close();
}
}
This will take in the number of lines, then two points on each line seperated by spaces. If I enter
2
3 -1 0 8
3 -1 0 -2
It works fine, finding the point (3, -1)
However, if I put in the same values reversed
2
3 -1 0 -2
3 -1 0 8
It gives me (-3.0, 6.999999999999999) which is wrong
What is going wrong with the code? I can't pinpoint where the problem comes from.
Sorting by slopes may mix your input data in your version.
If you want to swap the lines, swap all line data:
for (int j = 0; j < lines - 1; j++) { //sorts the array by slopes
if (lineMXYC[0][j] > lineMXYC[0][j + 1]) {
for (int i = 0; i < 4; i++) {
double TEMP = lineMXYC[i][j + 1];
lineMXYC[i][j + 1] = lineMXYC[i][j];
lineMXYC[i][j] = TEMP;
}
}
}
If I may give you an advice:
make a separate Line class for better design
implement the compare method or a line comparator
use some sorting algorithm, the one you use will not sort correctly for more lines, e.g. see Java Tutorials

Categories

Resources