i want to create a 10x10 matrix(with user input)
for e.g., i have given a small sample of 2x2 matrix and below is the description regarding what manipulation i want to do.
say for e.g my matrix is
0.76 1
0 0.3
now what i want to do is that, whenever the value in the matrix is greater than 0.25, i want to print 1 and if it is less than 0.25 than i want to print 0 and if it is 0 or 1 then let it be as it is....
so the answer for my above matrix should be
1 1
0 0
Software/Hardware used:
ASKED:
October 6, 2010 6:52 AM
UPDATED:
October 6, 2010 2:46 PM
Yashpal, that seems to be your homework. It is not a good idea to ask for the solution here.
However, if you post your current code and ask for help on a specific problem/doubt, the community could offer some guidance.
This is the code which i have written. Although i have given the elements here itself, as my immediate need is to manipulate the matrix… but can’t get the required output. in fact, it shows me error. plz help.
public class Matrix
{
public static void main(String args[])
{
double val[][]={
{1, 0.76, 0.64, 0.11, 0.05, 0, 0, 0.12, 0.15, 0},
{0.76, 1, 0.32, 0, 0.67, 0.13, 0.23, 0.43, 0, 0.05},
{0.64, 0.32, 1, 0.13, 0.24, 0, 0, 0.15, 0, 0},
{0.11, 0, 0.13, 1, 0.54, 0.83, 0.57, 0, 0, 0},
{0.05, 0.67, 0.24, 0.54, 1, 0.2, 0.41, 0.2, 0.23, 0},
{0, 0.13, 0, 0.83, 0.2, 1, 0.69, 0.15, 0, 0},
{0, 0.23, 0, 0.57, 0.41, 0.69, 1, 0.18, 0, 0.12},
{0.12, 0.43, 0.15, 0, 0.2, 0.15, 0.18, 1, 0.84, 0.61},
{0.15, 0, 0, 0, 0.23, 0, 0, 0.84, 1, 0.65},
{0, 0.05, 0, 0, 0, 0, 0.12, 0.61, 0.65, 1}
};
double th[][] = {{0.25,0.25}};
int i,j;
for(i=0; i<val.length;i++)
{
int count = 1;
for(j=0;j<val[i].length;j++)
{
if (val[i][j] < th[i][j])
System.out.println(count);
}
}
}
}
is it a compile time or run time error ?
What is the error message ?
What is the line of code causing the error ?