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?

Closed due to the fact that the participants are off topic: Yuri Spb , Alexey Shimansky , VenZell , D-side , Nick Volynkin Jun 3 '16 at 6:19 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Yuriy SPb, Alexey Shimansky, VenZell, Nick Volynkin
If the question can be reformulated according to the rules set out in the certificate , edit it .

    1 answer 1

    After the case "cylinder": you should not break

      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("В списке нет Ваших команд"); } break; 
    • There, break cannot be set, otherwise the following switch statement will not see the UserReqCylinder variable. - Miron Fisenko
    • @MironFisenko, you are wrong. Look where exactly you missed the break - YuriySPb
    • Yes, thanks, now it is reached - Miron Fisenko
    • @MironFisenko, pzh-ta) After the default, it is also better to put a break - and then something happens and you’re looking for something - YuriySPb