Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Masuzu{
- public static void main (String []args){
- float A [ ] [ ] = {
- {1f, -2f, 3f},
- {5f, 6f, 7f},
- {-9f, 10f, 11f}
- };
- float B [ ] [ ] = {
- {3f, 6f, 1f},
- {12f, 2f, -9f},
- {-4f, 11f, 8f}
- };
- System.out.println("Матрица A: ");
- vivod(A);
- firstmin(A);
- System.out.println("Вектор максимальных: ");
- vivodArray(vector(A));
- System.out.println("Матрица B: ");
- vivod(B);
- System.out.println("Результат умножения матрицы A на B: ");
- vivod(umnozh(A,B));
- }
- public static void firstmin (float A[][]){
- boolean found = false;
- for (int i=0; i<A.length-1 && !found; i++) {
- for (int j=i+1; j< A[i].length && !found; j++){
- if (A[i][j]<0) {
- System.out.println("Первый минимальный элемент: " + A[i][j]);
- found = true;
- }
- }
- }
- }
- public static void vivod (float A[][]){
- for (int i=0; i<A.length; i++){
- for (int j=0; j<A[0].length; j++)
- System.out.printf ("% 7.2f ",A[i][j]);
- System.out.println();
- }
- }
- public static void vivodArray (float A[]){
- for (int i=0; i<A.length; i++){
- System.out.printf ("% 7.2f ",A[i]);
- }
- System.out.println();
- }
- public static float[] vector (float A[][]){
- int lines = A.length;
- int columns = A[0].length;
- float[] maxArray = new float[columns];
- for (int j = 0; j < columns; j++) {
- float max = Math.abs(A[0][j]);
- for (int i = 1; i < lines; i++) {
- if (max < Math.abs(A[i][j])) {
- max = Math.abs(A[i][j]);
- maxArray[j] = A[i][j];
- }
- }
- }
- return maxArray;
- }
- public static float [ ][ ] umnozh (float A[ ][ ],float B[ ][ ]){
- if (A[0].length != B.length) return null;
- float [ ][ ] C = new float [A.length] [B[0].length];
- for (int i = 0; i < A.length; i++)
- for (int j = 0; j < B[0].length; j++){
- C[ i ][ j ] = 0;
- for (int k = 0; k < B.length; k++)
- C[ i ][ j ] = C[ i ][ j ] + A[ i ][ k ] * B[ k ][ j ];
- }
- return C;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement