js生成随机数并判断奇偶_创建一个随机数并检查它是奇数还是偶数

I am looking to create a batch file that, when ran, creates a random integer from 0 to 100 and then runs it through an if statement that checks whether it is odd or even.

I've been having some trouble, so here is what I have so far.

@echo off

set /a num=%random% %%100 +1

if ( num % 2 == 0 ) {

//even

}

else

{

//odd

}

The error I get is - "num was unexpected at this time"

解决方案@ECHO OFF

SETLOCAL

set /a num=%random% %%100 +1

SET /a nummod2=num %% 2

IF %nummod2% == 0 (ECHO %num% is even) ELSE (ECHO %num% is odd)

GOTO :EOF

Conventional IF syntax is if [not] operand1==operand2 somethingtodo where operand1 and operand2 are both strings. If the strings contain separators like Space,Tab or other characters that have a special meaning to batch then the string must be "enclosed in quotes".

Fundamentally, if compares strings. The operator must be one of a fixed set of operators [== equ neq gtr geq lss leq] hence cmd was objecting to num where it expected an operator.

A calculation cannot be performed within a if statement's parameters.

%% is required to perform the mod operation, since % is a special character that itself needs to be escaped by a %.

Note that { and } are ordinary characters with no special meaning to batch and remarks must follow

rem remark string

There is a commonly-used exploit which is

::comment

actually, a broken label, which can have unforeseen side-effects (like ending a code-block)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值