help in matrix

• 10-06-2010, 08:00 AM
Engineer
help in matrix
Hello,
i want make program of matrix
that user can enter rows and coulmns in matrix
i know that i must use two_dimantions array
but how i make it ,i tried alot and failed...
• 10-06-2010, 08:06 AM
JosAH
Quote:

Originally Posted by Engineer
but how i make it ,i tried alot and failed...

Well, time to go back to the drawing board ... A matrix is a two dimensional block of numbers. Do you want the sizes of that block to be adjustable on the go or do you want to 'set up' a matrix with the sizes given at construction time? What do you want to do with those matrixes? Just the 'normal' mathematical operations or more fancy stuff? Do those matrixes contain a lot of zeros, i.e. are they 'sparse'? Are those matrixes square matrixes? Any other structure imposed on the numberds they contain? (i.e. symmetrical, (tri)diagonal etc.) Do they contain complex numbers or just doubles? Are they extremely large?

kind regards,

Jos
• 10-06-2010, 09:02 AM
Engineer
iam student in faculty of engineering.......
there are some of lows in algebra very complex i want to solve it with java
in my program i want the user enter the program and ask him to indicate the size of matrix
example ::please enter the numbers of row
3
please enter the numbers of coulms
2
1 3
8 9

thats what i want ........:)
• 10-06-2010, 09:36 AM
JosAH
Quote:

Originally Posted by Engineer
iam student in faculty of engineering.......
there are some of lows in algebra very complex i want to solve it with java
in my program i want the user enter the program and ask him to indicate the size of matrix
example ::please enter the numbers of row
3
please enter the numbers of coulms
2
1 3
8 9

thats what i want ........:)

Ok, you've shown us what you want, now show us what you've tried. b.t.w. your matrix example has two rows and two columns, bad example.

kind regards,

Jos
• 10-06-2010, 09:49 AM
Engineer
oh, iam sorry for this example
1 3
8 9
5 6
i want to know how can i make that
how to make user enter his matrix but i cant
Scanner num= new Scanner(System.in);
System.out.print("Enter the number of your rows");
int row=num.nextInt();
System.out.print("Enter the number of your coulmns");
int coulm=num.nextInt();
int[][] mx = new int[row][coulm];
for(int r=0;r<row; r++)
for(int c=0;r<coulm; c++){
double ro=num.nextDouble();
mx [row][coulm]=(int) ro;

System.out.print(mx [row][coulm]);

}
• 10-06-2010, 09:54 AM
JosAH
Quote:

Originally Posted by Engineer
oh, iam sorry for this example
1 3
8 9
5 6
i want to know how can i make that
how to make user enter his matrix but i cant
Scanner num= new Scanner(System.in);
System.out.print("Enter the number of your rows");
int row=num.nextInt();
System.out.print("Enter the number of your coulmns");
int coulm=num.nextInt();
int[][] mx = new int[row][coulm];
for(int r=0;r<row; r++)
for(int c=0;r<coulm; c++){
double ro=num.nextDouble();
mx [row][coulm]=(int) ro;

System.out.print(mx [row][coulm]);

}

Please use code tags when you're posting code. What do you think that last line does? hint: matrix mx only has row rows and 'coulm' colums so those values are not valid index values. You should print the value of the current mx[r][c] instead.

Also: why are you reading 'double' values and cast them to ints? Why not just reads ints instead?

kind regards,

Jos
• 10-06-2010, 12:38 PM
Engineer
Scanner num= new Scanner(System.in);
System.out.print("Enter the number of your rows");
int row=num.nextInt();
System.out.print("Enter the number of your coulmns");
int coulm=num.nextInt();
int[][] mx = new int[row][coulm];
for(int r=1;r<row; r++){
for(int c=1;r<coulm; c++){
int ro=num.nextInt();
mx [r][c]= ro;

System.out.print(mx [r][c]);

}
}
this my code but there are errors in it???????
and didnt make what i want !!!!!!!!i tried
sorry, all options that make me put code in php are stop !!!!!!!
• 10-06-2010, 01:26 PM
JosAH
Quote:

Originally Posted by Engineer
Scanner num= new Scanner(System.in);
System.out.print("Enter the number of your rows");
int row=num.nextInt();
System.out.print("Enter the number of your coulmns");
int coulm=num.nextInt();
int[][] mx = new int[row][coulm];
for(int r=1;r<row; r++){
for(int c=1;r<coulm; c++){
int ro=num.nextInt();
mx [r][c]= ro;

System.out.print(mx [r][c]);

}
}
this my code but there are errors in it???????

Why didn't you put your code in [code] ... [/code] tags? Why don't you show us the errors you saw/read? Do you want us to guess? Do you think that's funny?

kind regards,

Jos