Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Matrix{
- static int[][] matrix = {
- { 1, 2, 3},
- { 4, 5, 6},
- { 7, 8, 9},
- {10, 11, 12}
- };
- public static boolean gleich(int[] a1, int[] a2) {
- boolean b = false;
- for (int i = 0; i<a1.length; i++){
- if (a1[i]==a2[i]){
- b = true;
- }else{
- return false;
- }
- }return b;
- }
- public static boolean enthaeltZeile(int[][] matrix, int[] zeile) {
- boolean b = false;
- for (int i = 0;i<matrix.length;i++){
- if (b==true){
- break;
- }for (int j = 0;j<matrix[i].length;j++){
- if (matrix[i][j]== zeile[j]){
- b = true;
- }else{
- b = false;
- break;
- }
- }
- }return b;
- }
- public static boolean enthaeltSpalte(int[][] matrix, int[] spalte) {
- boolean b = false;
- for (int j=0;j<matrix[j].length;j++){
- if (b==true){
- break;
- }
- for (int i=0;i<matrix.length;i++){
- if (matrix[i][j]==spalte[i]){
- b = true;
- }else{
- b = false;
- break;
- }
- }
- }return b;
- }
- public static int[][] transponieren(int[][] matrix) {
- int [][] trans = new int [matrix[0].length][matrix.length];
- for (int i = 0; i<matrix.length;++i){
- for (int j = 0; j<matrix[i].length;++j){
- trans[j][i] = matrix[i][j];
- }
- }return trans;
- }
- public static void main(String[] args) {
- System.out.println("gleich({1,2,3}, {1,2,3}): "
- + gleich(new int[]{1, 2, 3}, new int[]{1, 2, 3})); // true
- System.out.println("enthaeltZeile(matrix, {1,2,3}): "
- + enthaeltZeile(matrix, new int[]{1, 2, 3})); // true
- System.out.println("enthaeltSpalte(matrix, {1,4,7,10}: "
- + enthaeltSpalte(matrix, new int[]{1,4,7,10}));
- System.out.println("Vorher:");
- for(int k=0; k<=matrix.length-1;k++){
- for(int j=0; j<=matrix[0].length-1;j++){
- System.out.print(matrix[k][j]);
- }
- }
- System.out.println();
- System.out.println("Nachher:");
- for(int k=0; k<=matrix[0].length-1;k++){
- for(int j=0; j<=matrix.length-1;j++){
- System.out.print(transponieren(matrix)[k][j]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement