Verarbeitung Römische Zahlen hinzugefügt
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
/bin/
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>AB_Fallunterscheidungen</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.release=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=1.8
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class Rom {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner tastatur = new Scanner(System.in);
|
||||||
|
System.out.print("Eingabe römische Zahl > ");
|
||||||
|
String rZahl = tastatur.next();
|
||||||
|
|
||||||
|
int i;
|
||||||
|
int dezZahl = 0;
|
||||||
|
int lZahl = 0;
|
||||||
|
int zahl = 0;
|
||||||
|
byte gleich = 0;
|
||||||
|
int v = 0, l = 0, d = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < rZahl.length(); i++) {
|
||||||
|
if (rZahl.charAt(i) == 'V') {
|
||||||
|
v += 1;
|
||||||
|
} else if (rZahl.charAt(i) == 'L') {
|
||||||
|
l += 1;
|
||||||
|
} else if (rZahl.charAt(i) == 'D') {
|
||||||
|
d += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (v > 1 || l > 1 || d > 1) {
|
||||||
|
System.out.print("Eingabe ungültig!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < rZahl.length(); i++) {
|
||||||
|
switch (rZahl.charAt(i)) {
|
||||||
|
case 'I':
|
||||||
|
zahl = 1;
|
||||||
|
break;
|
||||||
|
case 'V':
|
||||||
|
zahl = 5;
|
||||||
|
break;
|
||||||
|
case 'X':
|
||||||
|
zahl = 10;
|
||||||
|
break;
|
||||||
|
case 'L':
|
||||||
|
zahl = 50;
|
||||||
|
break;
|
||||||
|
case 'C':
|
||||||
|
zahl = 100;
|
||||||
|
break;
|
||||||
|
case 'D':
|
||||||
|
zahl = 500;
|
||||||
|
break;
|
||||||
|
case 'M':
|
||||||
|
zahl = 1000;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// System.out.println("zahl " + zahl);
|
||||||
|
// System.out.println("lZahl " + lZahl);
|
||||||
|
// System.out.println("dZahl " + dezZahl);
|
||||||
|
if (zahl > lZahl && lZahl != 0) {
|
||||||
|
if ((lZahl == 1 && (zahl == 5 || zahl == 10)) || (lZahl == 10 && (zahl == 50 || zahl == 100))
|
||||||
|
|| (lZahl == 100 && (zahl == 500 || zahl == 1000))) {
|
||||||
|
dezZahl = (dezZahl - lZahl) + (zahl - lZahl);
|
||||||
|
} else {
|
||||||
|
System.out.print("Eingabe ungültig!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dezZahl += zahl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lZahl == zahl) {
|
||||||
|
gleich += 1;
|
||||||
|
} else {
|
||||||
|
gleich = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gleich >= 3) {
|
||||||
|
System.out.print("Eingabe ungültig!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lZahl = zahl;
|
||||||
|
|
||||||
|
}
|
||||||
|
System.out.print(dezZahl);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user