| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- /**
- * @author (Jakob Kienegger)
- * @version (27.04.19)
- */
- import java.io.*;
- import java.util.*;
- public class Eingabe
- {
- public Element[][] matrix;
- private double multi = 1;
- private int zeilenZahl;
- private int spaltenZahl;
- private double zahl;
- public Eingabe()
- {
- zeilenZahl = 3;
- spaltenZahl = 4;
- }
- public void einlesen() throws IOException {
-
- //InputStreamReader isr = null;
- BufferedReader br = null;
- matrix = new Element[zeilenZahl][spaltenZahl];
- for(int i = 0; i < zeilenZahl; i++) {
- for(int j = 0; j < spaltenZahl; j++) {
- try {
- br = new BufferedReader(new InputStreamReader(System.in));
- System.out.print(+ i + "," + j + ": ");
- String eingabe = br.readLine();
- matrix[i][j] = new Element(Integer.parseInt(eingabe));
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- if (br != null) {
- try {
- br.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
-
-
-
- public void ausgabe()
- {
- for(int j=0; j<zeilenZahl; j++)
- {
- for(int i=0; i<spaltenZahl; i++)
- {
- System.out.print( matrix[j][i].gibZahl() + ", ");
- }
- System.out.println("");
- }
- }
-
- public void zeileMulti(int zeile)
- {
- for(int i=0; i<spaltenZahl; i++)
- {
- matrix[zeile][i].multiZahl(this.multi);
- }
- }
-
- public void zeilenAddition(int zeileStatic, int zeileChange)
- {
- for(int i=0; i<spaltenZahl; i++)
- {
- this.zahl = matrix[zeileChange][i].gibZahl() - matrix[zeileStatic][i].gibZahl();
- matrix[zeileChange][i].changeZahl(this.zahl);
- }
- }
-
- public void gaussAlgorithmus(int zeilenZahl, int spaltenZahl)
- {
- for(int i=0; i<zeilenZahl; i++)
- {
- this.multi = 1/(matrix[i][i].gibZahl());
- for(int k=0; k<zeilenZahl; k++)
- {
- zeileMulti(k);
- }
-
- for(int j=0; j<i | j>i; j++)
- {
- zeilenAddition(i, j);
- }
-
- }
- }
-
- public static void main (String[] args) {
- Eingabe a = new Eingabe();
- //Gauss b = new Gauss(3, 4);
- try {
- a.einlesen();
- a.gaussAlgorithmus(3, 4);
- a.ausgabe();
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- }
-
- /*
-
- */
-
-
- }
|