package de.extrema.java;
import java.util.Scanner;
public class Pogramm {
public static void main(String arrg[]) {
try (Scanner scanner = new Scanner(System.in)) {
double a , b , r , A , h;
int number2;
int number;
System.out.println("Körper: ");
System.out.println("Deine Wahl: ");
number = scanner.nextInt();
number2 = scanner.nextInt();
switch(number) {
case 1:{
switch(number) {
System.out.println("Viereck: 1 Kreis: 2 Dreieck: 3 Trapez: 4 ");
case 1:{
System.out.println("a: ");
a = scanner.nextDouble();
System.out.println("b(a): ");
b = scanner.nextDouble();
A = a * b;
System.out.println("Fläche des Vierecks= " + A);
break;
}
case 2:{
System.out.println("r: ");
r = scanner.nextDouble();
A = Math.PI * r * r;
System.out.println("Fläche des Kreises= " + A);
break;
}
case 3:{
System.out.println("a: ");
a = scanner.nextDouble();
System.out.println("b: ");
b = scanner.nextDouble();
A = 0.5 * a * b;
System.out.println("Fläche des Dreiecks: " + A);
break;
}
case 4:{
System.out.println("a: ");
a = scanner.nextDouble();
System.out.println("b: ");
b = scanner.nextDouble();
System.out.println("h: ");
h = scanner.nextDouble();
A = (a + b)* h / 2;
System.out.println("Fläche des Trapezes: " +A);
break;
}
}
}
}
}
}
}
nxcx
0
Newbie Poster
Recommended Answers
Jump to PostYou can only get to line 17 if
number
is 1, so having a switch onnumber
at line 17 is pointless. Did you meannumber2
?
The switch on line 15 has only one case - what's the point of that?
Line 18 is invalid - all the code …
Jump to PostLine 5 has typo: arrg should be arg.
Why have 1 case on line 17? Just remove that.
You only need one case statement below it.
It is like this was entered in one hit instead of debugging as you went. This is not a good way to program - …
All 5 Replies
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
rproffitt
2,572
"Nothing to see here."
Moderator
wwwalker
49
Newbie Poster
DGPickett
20
Newbie Poster
Nutster
58
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.