forked from jean/GDP-Uebungen
files added
This commit is contained in:
Generated
+3
@@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_14" default="false" project-jdk-name="15" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/U4.iml" filepath="$PROJECT_DIR$/U4.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
Binary file not shown.
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,27 @@
|
||||
import java.util.Scanner;
|
||||
public class Maximum {
|
||||
public static void main(String[] args){
|
||||
System.out.print("Bitte geben Sie die Anzahl der Zufallszahlen an: ");
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
int arraySize = Integer.parseInt(scanner.next());
|
||||
double[] valueStore = new double[arraySize];
|
||||
for (int i=0; i<arraySize;i++){
|
||||
valueStore[i] = Math.random();
|
||||
System.out.println("#" + i + " : " + valueStore[i]);
|
||||
}
|
||||
|
||||
System.out.println("Die größte Zahl hat den index: " + max(valueStore));
|
||||
}
|
||||
public static int max(double input[]){
|
||||
int index=0;
|
||||
double largestNumber = 0;
|
||||
for(int i=0; i<input.length;i++){
|
||||
if(largestNumber<input[i]){
|
||||
largestNumber = input[i];
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
//import java.util.Scanner;
|
||||
import java.util.Arrays;
|
||||
public class Schnittmenge {
|
||||
public static void main(String[] args){
|
||||
//Scanner scanner = new Scanner(System.in);
|
||||
int[] set1a = {0, 1, 2, 3, 4, 5};
|
||||
int[] set1b = {3, 4, 5, 6, 7, 8};
|
||||
int[] set2a = {0, 1, 2, 3};
|
||||
int[] set2b = {4, 5, 6};
|
||||
int[] set3a = {0, 1, 2};
|
||||
int[] set3b = {0, 1, 2};
|
||||
System.out.println(Arrays.toString(schnittmenge(set1a, set1b)));
|
||||
System.out.println(Arrays.toString(schnittmenge(set2a, set2b)));
|
||||
System.out.println(Arrays.toString(schnittmenge(set3a, set3b)));
|
||||
|
||||
}
|
||||
|
||||
public static int[] schnittmenge(int[] arrA,int[] arrB){
|
||||
int resArrSize = 0;
|
||||
for(int numberA:arrA){
|
||||
for(int numberB:arrB){
|
||||
if(numberA==numberB) resArrSize++;
|
||||
}
|
||||
}
|
||||
int[] resultArr = new int[resArrSize];
|
||||
for(int numberA:arrA){
|
||||
for(int numberB:arrB){
|
||||
if(numberA==numberB) resultArr[--resArrSize] = numberA;
|
||||
}
|
||||
}
|
||||
return resultArr;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import java.util.Scanner;
|
||||
public class Wechselgeld {
|
||||
public static void main(String... args){
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
System.out.print("Bitte Preis engeben: ");
|
||||
float preis = Float.parseFloat(scanner.nextLine());
|
||||
System.out.print("Bitte Betrag engeben: ");
|
||||
float zahlung = Float.parseFloat(scanner.nextLine());
|
||||
if(wechselgeld(preis,zahlung)) System.out.println("Vielen Dank!");
|
||||
else System.out.println("Das reicht leider nicht.");
|
||||
}
|
||||
public static boolean wechselgeld(float sollWert, float istWert){
|
||||
float[] scheine = {100f, 50f, 20f, 10f, 50f};
|
||||
float[] muenzen = {2f, 1f, 0.50f, 0.20f, 0.10f, 0.05f, 0.02f, 0.01f};
|
||||
int[] anzScheine = new int[scheine.length];
|
||||
int[] anzMuenzen = new int[muenzen.length];
|
||||
if(istWert<sollWert) return false;
|
||||
else{
|
||||
float ruekGeld = istWert - sollWert;
|
||||
System.out.println("_______________ Scheine _____________");
|
||||
for(int i=0; i<scheine.length; i++){
|
||||
anzScheine[i] = (int) (ruekGeld / scheine[i]);
|
||||
ruekGeld -= scheine[i]*(float)anzScheine[i];
|
||||
if(anzScheine[i]>0) System.out.println(anzScheine[i] + " x " + scheine[i] + " EUR");
|
||||
}
|
||||
System.out.println("_______________ Muenzen _____________");
|
||||
for(int i=0; i<muenzen.length; i++){
|
||||
anzMuenzen[i] = (int) (ruekGeld / muenzen[i]);
|
||||
ruekGeld -= muenzen[i]*(float)anzMuenzen[i];
|
||||
if(anzMuenzen[i]>0) System.out.println(anzMuenzen[i] + " x " + (int)(muenzen[i]*100) + " ct");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user