在Swift数组中找到元素的总和(Finding sum of elements in Swift array)
在swift中找到整数数组的最简单(最佳)方法是什么? 我有一个数组称为倍数,我想知道这个倍数的总和。 先谢谢你!
What is the easiest (best) way to find the sum of an array of integers in swift? I have an array called multiples and I would like to know the sum of the multiples.
原文:https://stackoverflow.com/questions/24795130
更新时间:2023-05-22 10:05
最满意答案
是:
$boolean = !$boolean;
如果它不是一个布尔值,你可以使用三元结构:
$int = ($some_condition ? 1 : 2); // if $some_condition is true, set 1 // otherwise set 2
Yes:
$boolean = !$boolean;
if it's not a boolean value, you can use the ternary construction:
$int = ($some_condition ? 1 : 2); // if $some_condition is true, set 1 // otherwise set 2
相关问答
更多-
将布尔值传入指令(Passing Boolean Value Into Directive)[2019-06-15]
你做错了什么 readOnly:'@' 这意味着readOnly将是一个字符串,使其成为一个js变量尝试 readOnly:'=' 然后 应该 你需要显示更多的代码,这可能是错误的一部分,但我认为还有更多 希望能帮助到你 what you are doing wrong is readOnly:'@' this means r ... -
如果用户选择0,则只需要继续。 Scanner kb = new Scanner(System.in); // c = continue char c = 'a'; // attempt to limit the input to 3 times int attempt = 3; // option = op int op = 0; do { do{ System.out.println("Choose continue[0] or go out[1]."); wh ...
-
布尔值开关/反相(Boolean value switch/invert)[2022-01-05]
是: $boolean = !$boolean; 如果它不是一个布尔值,你可以使用三元结构: $int = ($some_condition ? 1 : 2); // if $some_condition is true, set 1 // otherwise set 2 Yes: $boolean = !$boolean; if it's not a boolean value, you can use the ternary co ... -
Android,Use switch case用于确定布尔值(Android,Use switch case is used to determine the boolean)[2023-08-16]
你想学习开关。 您可以将枚举用于您的目的, public enum BtnWifi { // you can create new enum java file for this CONNECTED, NOT_CONNECTED } //.... Setting value for enum in your code BtnWifi btnWifi; if(isConnected) { //if connection established btnWifi = BtnWifi.CONNECTED; ... -
将布尔值分配给整数(Assigning boolean values to integer)[2022-03-21]
你想要这样的东西: class SwitchBoard(object): def __init__(self, num_switches): # create a dict of {number: state} key-values self.switches = {i: False for i in range(num_switches)} def flip(self, num): # test for the number being o ... -
您可以随意更改bool的值。 至于if: if randombool == True: 有效,但您也可以使用: if randombool: 如果你想测试某些东西是否是假的,你可以使用: if randombool == False 但你也可以使用: if not randombool: You can change the value of a bool all you want. As for an if: if randombool == True: works, but you can a ...