关于JAVA的IF和循环语句的语法,不懂如何再次输入
这个是我已经做到的地步。。。可是之后就不懂做了。。。要求是在数完50次绵羊后,再次询问“Stillcan'tsleep,wouldyouliketocountagain?...
这个是我已经做到的地步。。。可是之后就不懂做了。。。
要求是在数完50次绵羊后,再次询问“Still can't sleep, would you like to count again?”
如果是,则继续数50次绵羊,直到答案不是“YES”。
请问,该怎样编辑。。。
<html>
<head>
<title>
Assignment Sample Loop
</title>
</head>
<Body>
<script type="text/javascript">
var name;
var answer;
var count;
count=0;
name=prompt("Please Enter Your Name");
document.write("Hello ", name, ", can't sleep?", "<br>");
answer=prompt("Would you like to count sheep?");
if(answer=="yes")
{while(count!=50)
{
count=count+1;
document.write("Sleep ");
}
}
</script>
</body>
</html> 展开
要求是在数完50次绵羊后,再次询问“Still can't sleep, would you like to count again?”
如果是,则继续数50次绵羊,直到答案不是“YES”。
请问,该怎样编辑。。。
<html>
<head>
<title>
Assignment Sample Loop
</title>
</head>
<Body>
<script type="text/javascript">
var name;
var answer;
var count;
count=0;
name=prompt("Please Enter Your Name");
document.write("Hello ", name, ", can't sleep?", "<br>");
answer=prompt("Would you like to count sheep?");
if(answer=="yes")
{while(count!=50)
{
count=count+1;
document.write("Sleep ");
}
}
</script>
</body>
</html> 展开
3个回答
展开全部
answer=prompt("Would you like to count sheep?");
if(answer == yes)
while(!(count / 50)) //如果count 还没有开始数,或是50
{ //倍数,循环开始,count 初始为0
answer=prompt("Still can't sleep, would you like to count again?");
if(answer == no)
break;//我用的是C++的语法,我想应该是一样的
else
while((++count/50))//如果count是50的倍数,循环退出
{
document.write("Sleep ");
}
}
楼上那样写,如果YES后,应该是个无限循环,count在第一次超过50后,永远再也不会==50了,除非在函数内部定义count.
if(answer == yes)
while(!(count / 50)) //如果count 还没有开始数,或是50
{ //倍数,循环开始,count 初始为0
answer=prompt("Still can't sleep, would you like to count again?");
if(answer == no)
break;//我用的是C++的语法,我想应该是一样的
else
while((++count/50))//如果count是50的倍数,循环退出
{
document.write("Sleep ");
}
}
楼上那样写,如果YES后,应该是个无限循环,count在第一次超过50后,永远再也不会==50了,除非在函数内部定义count.
展开全部
兄台,你这个是JSP(Java script,一种脚本语言),不是JAVA;晕阿。
JSP的语法我不太懂,写C的又怕你看不懂,掺杂伪代码说一下吧,大致思路九十一个二重循环,外层判断anwer,内层判断count:
while (answer==YES)
{
while (count!=50)
{
输入数羊语句;
count++;
}
answer=prompt("Would like to count sleep?\n");
}
JSP的语法我不太懂,写C的又怕你看不懂,掺杂伪代码说一下吧,大致思路九十一个二重循环,外层判断anwer,内层判断count:
while (answer==YES)
{
while (count!=50)
{
输入数羊语句;
count++;
}
answer=prompt("Would like to count sleep?\n");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
连语言都搞错了啊,JAVASCRIPT不等于JAVA,不要看到有JAVA的就说JAVA语言
if (answer==YES)
{
while (count<=50)
{
输入数羊语句;
count++;
}
answer=prompt("Would like to count sleep?\n");
}
if (answer==YES)
{
while (count<=50)
{
输入数羊语句;
count++;
}
answer=prompt("Would like to count sleep?\n");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询