I wrote a program that can calculate the volume and area of a cylinder and the perimeter and area of a circle. Here is the code:
public class Prigramm { public static void main(String[] args) { double pi = 3.14; System.out.println("Чтобы вызвать формулы цилиндра, введите cylinder"); System.out.println( "Чтобы вызвать формулы круга, введите circle"); Scanner scan = new Scanner(System.in); String UserRequest = scan.nextLine(); switch(UserRequest){ case "cylinder": System.out.println("Чтобы вызвать площадь цилиндра введите Scylinder"); System.out.println("Чтобы вызвать объем цилиндра введите Vcylinder"); String UserReqCylinder = scan.nextLine(); switch(UserReqCylinder){ case "Vcylinder": System.out.println("Введите радиус: "); int UserReqCylinderRad = scan.nextInt(); System.out.println("Введите высоту: "); int UserReqCylinderH = scan.nextInt(); double VCyl = pi * UserReqCylinderRad * UserReqCylinderRad * UserReqCylinderH; System.out.println("Объем равен " + VCyl); break; case "Scylinder": System.out.println("Введите радиус: "); int UserReqCylinderRad1 = scan.nextInt(); System.out.println("Введите высоту: "); int UserReqCylinderH1 = scan.nextInt(); double SCyl = pi * 2 * UserReqCylinderRad1 * UserReqCylinderH1; System.out.println("Площадь равна " + SCyl); break; default: System.out.println("В списке нет Ваших команд"); } case"circle": System.out.println("Чтобы вызвать площадь круга введите Scircle"); System.out.println("Чтобы вызвать периметр круга введите Pcircle"); String UserReqCircle = scan.nextLine(); switch(UserReqCircle){ case"Pcircle": System.out.println("Введите радиус "); int UserReqCircleRad = scan.nextInt(); double PCir = 2*pi*UserReqCircleRad; System.out.println("Длина окружности равна " + PCir); break; case "Scircle": System.out.println("Введите радиус"); int UserReqCircleRad1 = scan.nextInt(); double SCir = pi * UserReqCircleRad1 * UserReqCircleRad1; System.out.println("Площадь круга равна " + SCir); break; default: System.out.println("В списке нет Ваших команд"); } } } } When I enter, cylinder, and then Vcylinder or Scylinder, the following is displayed:
cylinder To call the cylinder area enter Scylinder
To call cylinder volume enter Vcylinder
Vcylinder
Enter the radius:
(entered radius)
Enter height:
(entered height)
Volume is (volume)
(and the most interesting thing here. The switch cycle should have stopped at this, but for some reason, immediately after the answer, the following is displayed :)
Type Scircle to bring up the area of the circle.
To call the perimeter of the circle, enter Pcircle
There are no teams in the list.
(and the program ends)
What is the problem?