Compare commits
merge into: Christian.Pape:master
Christian.Pape:master
joergkreiker:master
pull from: joergkreiker:master
joergkreiker:master
Christian.Pape:master
9 Commits
Author | SHA1 | Message | Date |
---|---|---|---|
Prof. Dr. Rainer Todtenhöfer | 5b0fd918c7 |
Final Version
|
7 years ago |
Sebastian Rieger | b46a1547ca |
added initial content for networking section
|
7 years ago |
Joerg Kreiker | 263acc51c4 |
Java Muster in .tex eingebaut
|
7 years ago |
Joerg Kreiker | 871f07bd0d |
fertige Rainer Loesung
|
7 years ago |
Prof. Dr. Rainer Todtenhöfer | 79f81c4313 |
Neue Datei
|
7 years ago |
Joerg Kreiker | 91c9d031c9 |
regex questions added
|
7 years ago |
Joerg Kreiker | 7b074cdffd |
added algodat questions
|
7 years ago |
Joerg Kreiker | 1180e009a2 |
added programming exercise
|
7 years ago |
Joerg Kreiker | b705ea336a |
Changed Style
|
7 years ago |
5 changed files with 273 additions and 19 deletions
-
181gsd-questions.tex
-
BINimages/logo.jpg
-
BINimages/mac-address.png
-
BINimages/tcp-handshake-and-flowcontrol.png
-
111todten/GSDSolution.java
After Width: 2362 | Height: 591 | Size: 232 KiB |
After Width: 1444 | Height: 471 | Size: 145 KiB |
After Width: 1376 | Height: 672 | Size: 76 KiB |
@ -0,0 +1,111 @@ |
|||||
|
/* |
||||
|
* To change this license header, choose License Headers in Project Properties. |
||||
|
* To change this template file, choose Tools | Templates |
||||
|
* and open the template in the editor. |
||||
|
*/ |
||||
|
package gsdsolution; |
||||
|
|
||||
|
/** |
||||
|
* |
||||
|
* @author todten |
||||
|
*/ |
||||
|
import java.math.*; |
||||
|
import java.util.*; |
||||
|
|
||||
|
public class GSDSolution { |
||||
|
|
||||
|
/* Main Program */ |
||||
|
public static void main(String[] args) { |
||||
|
|
||||
|
int someCows = 10; |
||||
|
|
||||
|
System.out.println(someCows + " cows have " + countLegs(someCows) + " legs \n"); |
||||
|
|
||||
|
System.out.println("Calculate Row Vector"); |
||||
|
calcAbsRowVector(inputMatrix); |
||||
|
|
||||
|
System.out.println("Merge and Sort Arrays"); |
||||
|
mergeAndSortArrays(input1, input2); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
/* Third Exercise */ |
||||
|
|
||||
|
public static int countLegs(int cows) { |
||||
|
if (cows == 0) { |
||||
|
return 0; |
||||
|
} else { |
||||
|
return 4 + countLegs(cows - 1); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/* First Exercise */ |
||||
|
|
||||
|
static int[][] inputMatrix = new int[][]{ |
||||
|
{2, 2}, |
||||
|
{4, 4}, |
||||
|
{6, 5}}; |
||||
|
|
||||
|
public static double[] calcAbsRowVector(int[][] aMatrix) { |
||||
|
|
||||
|
double[] result = new double[aMatrix.length]; |
||||
|
double temp = 0.0; |
||||
|
|
||||
|
for (int i = 0; i < aMatrix.length; i++) { |
||||
|
for (int j = 0; j < aMatrix[i].length; j++) { |
||||
|
temp = temp + Math.pow(aMatrix[i][j], 2); |
||||
|
//System.out.println(" I = " + i + " J = " + j + " Temp = " + temp); |
||||
|
} |
||||
|
result[i] = Math.sqrt(temp); |
||||
|
temp = 0.0; |
||||
|
//System.out.println(" Result at I " + i + " Result " + result[i]); |
||||
|
} |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
/* Second Exercise */ |
||||
|
|
||||
|
static int[] input1 = new int[]{2, 7, 5, 34}; |
||||
|
static int[] input2 = new int[]{3, 48, 4, 72}; |
||||
|
|
||||
|
public static int[] mergeAndSortArrays(int[] firstArray, int[] secondArray) { |
||||
|
|
||||
|
int[] resultArray = new int[firstArray.length * 2]; |
||||
|
/* OK, both Arrays are the same size */ |
||||
|
|
||||
|
int offset = firstArray.length; |
||||
|
|
||||
|
for (int i = 0; i < firstArray.length; i++) { |
||||
|
resultArray[i] = firstArray[i]; |
||||
|
} |
||||
|
for (int i = 0; i < secondArray.length; i++) { |
||||
|
resultArray[i + offset] = secondArray[i]; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
/* Just for debugging */ |
||||
|
System.out.println("Result Array " + Arrays.toString(resultArray)); |
||||
|
|
||||
|
/* |
||||
|
* Die haeufigste Antwort wird die Verwendung der build - in Funktion |
||||
|
* von Java zum Sortieren von Arrays sein |
||||
|
*/ |
||||
|
|
||||
|
Arrays.sort(resultArray); |
||||
|
|
||||
|
/* |
||||
|
* Dann nachfragen und den Bewerber das Array manuell mit einem |
||||
|
* Algorithmus seiner Wahl (z.B. Quicksort oder einfache Maximumssuche) |
||||
|
* sortieren lassen |
||||
|
*/ |
||||
|
|
||||
|
/* Just for debugging */ |
||||
|
System.out.println("Sorted Result Array " + Arrays.toString(resultArray)); |
||||
|
|
||||
|
return resultArray; |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue