Guest User

Untitled

a guest
Jul 18th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. package hausaufgabe5.la;
  2.  
  3. import java.io.IOException;
  4. import java.util.NoSuchElementException;
  5. import java.util.Scanner;
  6.  
  7. public final class Matrix {
  8.  
  9. private double[][] m;
  10. private int zeilenZahl;
  11. private int spaltenZahl;
  12.  
  13. public Matrix(int zeilenZahl, int spaltenZahl){
  14. m = new double[zeilenZahl][spaltenZahl];
  15. }
  16. public Matrix(Scanner scan) throws IOException {
  17. String inputLine;
  18. try {
  19. inputLine = scan.nextLine();
  20. zeilenZahl = Integer.parseInt(inputLine);
  21. inputLine = scan.nextLine();
  22. spaltenZahl = Integer.parseInt(inputLine);
  23. m = new double[zeilenZahl][spaltenZahl];
  24.  
  25. for (int i = 0; i < zeilenZahl; i++) {
  26. inputLine = scan.nextLine();
  27. String[] lineTokens = inputLine.split("\\s+");
  28. for (int j = 0; j < spaltenZahl; j++){
  29. m[i][j] = Double.parseDouble(lineTokens[j]);
  30. }
  31. }
  32. } catch (NumberFormatException e) {
  33. throw new IOException("Ungueltiger Dateiinhalt");
  34. } catch (NoSuchElementException e) {
  35. throw new IOException("Ungueltiger Dateiinhalt");
  36. }
  37. }
  38. private Matrix coMatrix(int x, int y) throws IllegalArgumentException {
  39. Matrix coMatrix = new Matrix(zeilenZahl-1, spaltenZahl-1);
  40. int f = -1;
  41. for(int g = 0; g < zeilenZahl; g++){
  42. if(g==x){
  43. g++;
  44. }
  45. f++;
  46. for(int h = 0; h < spaltenZahl-1; h++){
  47. coMatrix.m[f][h] = m[g][h+1];
  48. }
  49. }
  50. return coMatrix;
  51. }
  52. public int getZeilenZahl() {
  53. int zeilenZahl=m.length;
  54. return zeilenZahl;
  55. }
  56. public int getSpaltenZahl() {
  57. int spaltenZahl=m[0].length;
  58. return spaltenZahl;
  59. }
  60.  
  61.  
  62. }
Add Comment
Please, Sign In to add comment