I want to write a java code which based upon the Matrix.I am using jama matrix.
The code is like that:
import Jama.Matrix;
public class Landmarkassist {
public static void main(String args[]){
double [] time1st
{1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0};// Array of some 1st time slot.
double[] time2nd={2.0,3.0,6.0,7.0,8.0};//Array of 2nd time slot
double[] code={40.0,20.0,10.0,40.0,10.0};// Value of Marks
Matrix Calculation=new Matrix(8,8);// A 8*8 Jama Matrix
int k1=0,k2=0,l2=0,l1=0;
while(k1<time1st.length && k2<time2nd.length){
if(time1st[k1]<time2nd[k2]) {
//Just to increment counter k1++
k1++;
}
//If time slot 1 is equal to time slot 2 the we check for the codes if the codes matches with our criteria we update the cell of Jama matrix
else if(time1st[k1]==time2nd[k2]){
if(code[l1]==40.0){
Calculation.set(l2,k1,40.0);//set the value to a specific cell of Jama Matrix l2 reperesent row number and k1 represent column no, and 40.0 is the value of that Cell
l2++;
}
else if(code[l1]==20.0){
Calculation.set(l2,k1,20.0);
l2++;
}
else if(code[l1]==10.0){
Calculation.set(l2,k1,10.0);
l2++;
}
else{
System.out.println("Nothing to do");
}
k2++;
l1++;
}
}
Calculation.print(9,1);
}
}
Output:
0.0 40.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 20.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 10.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 40.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 10.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
Desired output:
0.0 40.0 40.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 20.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 10.0 10.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
That means all the same number of Marks should allocated at the same row. All the marks 40.0 is allocated at 1st row. All the marks 10.0 is allocated at 3rd row etc.
How could I iterate the loops to achieve this?
Thank you in advance