Guest User

Matrix File Reader

a guest
Jan 7th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. import java.util.Arrays;
  4. public class Determinant
  5. {
  6. public static void main(String args[]) throws IOException
  7. {
  8. int a [][] = new int[3][3];
  9. Scanner sf = new Scanner(new File("U:\\DataStructures\\Matrices\\Det3X3Data.in"));
  10. int maxIndx = -1;
  11. String text[] = new String[1000];
  12. while(sf.hasNext())
  13. {
  14. maxIndx++;
  15. text[maxIndx] = sf.nextLine( );
  16. }
  17. sf.close();
  18. int j = 0;
  19. int r1 = a.length;
  20. int c1 = a[0].length;
  21. do{
  22. if(text[j].equals("matrix")){
  23. j++;
  24. }
  25. else if(text[j].equals("row"))
  26. j++;
  27. else{
  28. if(matrix==1){
  29. while(!text[j].equals("matrix")){
  30. for(int k = 0; k<r1-1; k++){
  31. for(int i = 0; i<c1-1;i++){
  32. if(text[j].equals("row"))
  33. j++;
  34. else{
  35. int num = Integer.parseInt(text[j]);
  36. a[k][i]=num;
  37. System.out.println(a[k][i]);
  38. j++;
  39. }
  40. }
  41. }
  42. }
  43. }
  44. }
  45. }while(j<maxIndx);
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment