u18 & u20
This commit is contained in:
parent
7bfb8cbc0c
commit
9376c0bd7c
Binary file not shown.
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
* Klasse zum kodieren / dekodieren von Strings
|
||||
*/
|
||||
public class Encode {
|
||||
|
||||
/**
|
||||
* Tests der encode und decode Funktionen
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
System.out.println("encode(\"Hallo\") gibt zurück: " + encode("Hallo"));
|
||||
System.out.println("decode(\"Ibmmp\") gibt zurück: " + decode("Ibmmp"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Kodiert einen String durch eine alphabetische Verschiebung um 1
|
||||
*/
|
||||
public static String encode(String str) {
|
||||
String encoded = "";
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
encoded = encoded + (char)(str.charAt(i) + 1);
|
||||
}
|
||||
return encoded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dekodiert einen String der von encode Kodiert wurde
|
||||
*/
|
||||
public static String decode(String str) {
|
||||
String decoded = "";
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
decoded = decoded + (char)(str.charAt(i) - 1);
|
||||
}
|
||||
return decoded;
|
||||
}
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,19 @@
|
|||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Klasse zum Ausgeben von zufaelligem Text
|
||||
*/
|
||||
public class RandomText {
|
||||
public static void main(String[] args) {
|
||||
Random random = new Random();
|
||||
|
||||
String vocals = "aeiou";
|
||||
|
||||
for (int lines = random.nextInt(4) + 5; lines > 0; lines--) {
|
||||
for (int chars = random.nextInt(3) + 4; chars > 0; chars--) {
|
||||
System.out.print(vocals.charAt(random.nextInt(5)));
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue