Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. /**
  2. * r1,c2--Final Output
  3. * r2,c1--Condition
  4. */
  5. package helloworld;
  6. import java.io.*;
  7. import java.util.Scanner;
  8. /**
  9. * @author pradeep_7
  10. */
  11. public class Helloworld {
  12. public static void main(String[] args)throws IOException {
  13. Scanner hello = new Scanner(System.in);
  14. int r1,c1,r2,c2,i,j = 0,k;
  15. System.out.println("1St Matrix Row AND Column");
  16. r1=hello.nextInt();
  17. c1=hello.nextInt();
  18. System.out.println("2nd Matrix Row and Column");
  19. r2=hello.nextInt();
  20. c2=hello.nextInt();
  21. int[][] a = new int[30][30];
  22. int[][] b =new int[30][30];
  23. int[][] c = new int[30][30];
  24. //Reading 1st Matrix Machaaa
  25. System.out.println("1st Matrix Input");
  26. for(i=0;i<r1;i++)
  27. for(j=0;j<c1;j++)
  28. a[i][j]=hello.nextInt();
  29. //Reading Second Matrix Machaa
  30. System.out.print("2nd Matrix Input\n");
  31. for(i=0;i<r2;i++)
  32. for(j=0;j<c2;j++)
  33. b[i][j]=hello.nextInt();
  34. //Finally Loveda LO Logi****
  35. for(i=0;i<r1;i++)
  36. for(j=0;j<c2;j++)
  37. // c[i][j]=0;
  38. for(k=0;k<c1;k++)
  39. c[i][j]=c[i][j]+a[i][k]*b[k][j];
  40.  
  41. //Printting Fasak
  42. for(i=0;i<r1;i++)
  43. for(j=0;j<c2;j++)
  44. System.out.print(" "+c[i][j]);
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement