JavaRush /Java Blog /Random EN /Codes, inc; Room #003
Sultan
Level 16

Codes, inc; Room #003

Published in the Random EN group

Cake

Codes, inc;  Room #003 - 1 For his birthday, Petya bought a beautiful and delicious cake, which had a perfectly round shape. Petya did not know how many guests would come to his birthday, so he was forced to develop an algorithm according to which he could quickly cut the cake into N equal parts. Please note that cake cuts can be made both along the radius and across the diameter. Help Petya solve this problem by determining the smallest number of cuts of the cake given the number of guests (guests >= 1) . Write a public static int solve(int guests) function to solve this problem. Add. task: Try to solve the problem without using conditions and ternary operators ("?:"). Solution: public static int solve(int guests) { return (guests + 1) / (guests % 2 + 1); }
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION