帮助程序,while循环和equals() [英] Help with program, while loops and equals()
本文介绍了帮助程序,while循环和equals()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我累了,迷路了,周五晚上坐在这里试图完成我的节目。该程序提示用户输入一系列动物名称和声音,并从歌曲Old MacDonald have a farm中打印相应的经文。该程序将继续打印经文,直到用户输入不再为止。而不是动物的名字和声音。这就是我到目前为止:
展开 | 选择 | Wrap | 行号
解决方案
嗯,除了推荐你把你的逻辑改为
而(声音读入!=不再多)
{
做你所有的解析和打印
}
除此之外,我错过了你的问题。你有部分问题吗?看起来你到目前为止有一个良好的开端...
好吧,除了建议您将逻辑稍微更改为
while(声音读入!=不再多)
{
执行所有解析和打印
}
除此之外,我错过了你的问题。你有部分问题吗?看起来你到目前为止有一个良好的开端...
我们应该使用equals()来比较字符串而不是==!=等。
你不应该把你带进的程序......
假设你读了动物和噪音;
要求用户在空格分隔的一行中输入它们,例如:cow moooo
所以可以输入:不再 - - 像这样!!
//这样读了
input = studin.nextline()
//检查
I am tired and lost, sitting here on a Friday night trying to finish my program. The program prompts the user to enter a series of animal names and sounds, and print the corresponding verses from the song "Old MacDonald had a farm". The program will continue printing verses until the user enters "no more" instead of an animal name and sound. This is what I have so far:
Expand|Select|Wrap|Line Numbers
解决方案
Well, aside of recommending that you change your logic a bit to
while (sound read in != "no more")
{
do all your parsing and printing
}
aside of that, I missed your question. Were you having trouble with part of it? Looks like you have a good start so far...
Well, aside of recommending that you change your logic a bit to
while (sound read in != "no more")
{
do all your parsing and printing
}
aside of that, I missed your question. Were you having trouble with part of it? Looks like you have a good start so far...We are supposed to use equals() for comparing strings not the == != etc.
you should no what you are taking into the progam...
suppose you read-in "animal" and "noise";
ask user to enter them in one line separated by space eg: cow moooo
so it possible to enter: no more--like this!!
//read like this
input = studin.nextline()
//check
这篇关于帮助程序,while循环和equals()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取
|
15天全站免登陆