2-4 编程练习
来源:2-4 编程练习
蒋小贱贱贱
2017-11-12 22:49:15
<?php
for($i = 0; $i <= 50; $i++) {
echo $i;
}
echo "<br>";
for($i = 0; $i <4; $i++) {
switch($i) {
case 0:
$num = rand(0, 9);
break;
case 1:
$num = rand(0, 9);
break;
case 2:
$num = rand(0, 9);
break;
case 3:
$num = rand(0, 9);
break;
}
echo '<span style="color: #'.randColor().'">'.$num.'</span>';
}
function randColor(){
$colors = array();
for($i = 0;$i<6;$i++){
$colors[] = dechex(rand(0,15));
}
return implode('',$colors);
}
?>
1回答
guly
2017-11-13
你好,要求循环输出0-50之间的偶数,如果$i%2求余等于0,则输出$i,循环代码如下:
for($i = 0; $i <= 50; $i++) {
if($i%2==0){
echo $i;
}
}其他代码逻辑都是正确的,如果解决了您的问题请采纳,祝学习愉快!
相似问题