所有,我的教授给了我们以下循环用于本周的任务:
char *ptr1, *ptr2;
char c;
ptr1 = &arr[0];
ptr2 = &arr[idx-1];
while(ptr1 < ptr2){
c = *ptr1;
*ptr1 = *ptr2;
*ptr2 = c;
ptr1++;
ptr2--;
}
Run Code Online (Sandbox Code Playgroud)
这是关于ptr1与ptr2的位置吗?程序反转c_str并且工作正常,我只是不明白为什么.
我有一个非常奇怪的问题.我正在查询数据并将其格式化为json.格式工作得很好,但是当我尝试添加一个案例来防止,出现在json的最后一项时,我的SQL语句的"按日期排序"不起作用,我只是通过ID命令它.有什么想法?
$sql = "SELECT * FROM events ORDER BY date";
$res = mysql_query($sql,$con);
$number = mysql_num_rows($res);
$json = 'var event_data={';
$i = 1;
while ($row = mysql_fetch_assoc($res))
{
$json .= '"'.$row['id'].'": {';
$json .= '"loc_id":"'.$row['loc_id'].'"';
$json .= ', "type":"'.$row['type'].'"';
$json .= ', "time":"'.$row['time'].'"';
$json .= ', "date":"'.$row['date'].'"}';
if ($i < $number)
{
$json .= ','; //<----- this is the problem child
}else{
$json .= '';
}
$i ++;
}
$json .= '};';
echo $json;
Run Code Online (Sandbox Code Playgroud) 下面的代码询问用户他/她想要多少赛车手.
while (true) { // loops forever until break
try { // checks code for exceptions
System.out.println("How many racers should" + " participate in the race?");
amountRacers = in.nextInt();
break; // if no exceptions breaks out of loop
}
catch (InputMismatchException e) { // if an exception appears prints message below
System.err.println("Please enter a number! " + e.getMessage());
continue; // continues to loop if exception is found
}
}
Run Code Online (Sandbox Code Playgroud)
如果在amoutnRacers = in.nextInt();代码中输入一个数字,则循环出来并且程序的其余部分运行正常; 但是,当我输入诸如"awredsf"之类的内容时,它应该捕获该异常,它会这样做.而不是再次提示用户它不断循环,这对我来说没有意义.
程序在连续循环时打印如下:
有多少参赛者应参加比赛?有多少参赛者应参加比赛?有多少参赛者应参加比赛?有多少参赛者应参加比赛?有多少参赛者应参加比赛?有多少参赛者应参加比赛?有多少赛车手参加比赛?请输入一个号码!null请输入一个数字!null请输入一个数字!null请输入一个数字!null请输入一个数字!null请输入一个数字!null请输入一个数字!空值 ...
我不明白发生了什么amountRacers …
java exception-handling try-catch while-loop inputmismatchexception
我是编程新手,之前没有在我的应用程序中使用'while'语句.我有一个cocoapod动画圆圈计时器图形.完成动画后,它会将'didFinish'BOOL设置为'true'.我能够成功检查这个变量,但是当我告诉我的应用程序将我的一个按钮标签设置为特定文本'而'didFinish为false时,它会冻结我的应用程序.
//start the timer and change the label to "Reset"
else {
brewingTimer.start()
buttonSelect = 1
startTimer.setTitle("Reset", forState: .Selected)
//Start the circle counter graphic
circleCounterOuter.startWithSeconds(5)
circleCounterInner.startWithSeconds(2)
while circleCounterInner.didFinish == false {
startTimer.setTitle("Reset!", forState: .Selected)
}
startTimer.setTitle("Ok!", forState: .Selected)
}
Run Code Online (Sandbox Code Playgroud)
我点击"开始"的那一刻,应用程序冻结了.当我在while循环中为de-bugger设置一个断点时,应用程序似乎在我的语句中循环,因为我可以点击"跳过",因为它循环通过'while-loop'.但是当我解决问题时,我当然看不到我的动画在屏幕上运行,所以我不确定实际发生了什么导致模拟迟缓.
我有一个go函数,它会在Channel收到一些逻辑之后做一些逻辑.
我的问题是我希望函数在完成逻辑后保持活跃.我的想法是
我将在函数中添加无限循环.但是,我想知道这是不是
一个好的技术.我的守则如下:
func process(channel chan string, sid string) {
inputSid := <-channel
// check if sid exist in process pool
if strings.EqualFold(sid, inputSid) {
fmt.Println("Got message", sid)
//the code that I added to make this function alive
for {}
} else {
channel <- sid
//the code that I added to make this function alive
for {}
}
}
Run Code Online (Sandbox Code Playgroud) 你能告诉我我的代码有什么问题吗?
while(buttonPressed) {
setInterval(function () {
food = food + farms + (farmers/2);
updateFood();
}, 1000);
}
Run Code Online (Sandbox Code Playgroud)
我有一个食物价值,根据几个因素(农场,农民)自动,更快或不增加.它在没有循环的情况下运行良好,但由于某种原因,只有在我按下此按钮后才能执行此功能,这是我的问题.
我检查了控制台,并且var按钮默认为false,在我按下按钮后变为true,所以它应该工作:/我需要你的帮助:D
谢谢你们回复:)
我是python的新手,所以这可能是一个初学者的问题.我在下面的代码中的'else'语句出于语法错误而出于我的想法.我已多次查找它的语法,但我找不到错误.这是我的python代码:
siteswap = input("Enter the siteswap you want to validate here:")
aantal_digits = len(siteswap)
i = 0
j = 1
while i != aantal_digits:
if (int(siteswap[i])+ (i + 1)) % aantal_digits == (int(siteswap[1:aantal_digits])+ (j + 1)) % aantal_digits:
print("This siteswap is invalid")
break
elif i != aantal_digits:
del (int(siteswap[i])
else:
print ("This siteswap is valid")
break
Run Code Online (Sandbox Code Playgroud)
else突出显示,我收到"语法错误".
我有这个功能:
int change(float c)
{
float coins[] = {0.25, 0.10, 0.05, 0.01};
int count[] = {0, 0, 0, 0};
while(c > (0.00))
{
printf("I entered here\n");
if((c-coins[0]) >= (0.00))
{
c -= coins[0];
count[0]++;
printf("-0.25, c = %.2f\n", c);
}
else if((c-coins[1]) >= (0.00))
{
c -= coins[1];
count[1]++;
printf("-0.10, c = %.2f\n", c);
}
else if((c-coins[2]) >= (0.00))
{
c -= coins[2];
count[2]++;
printf("-0.05, c = %.2f\n", c);
}
else if((c-coins[3]) >= (0.00))
{
c -= coins[3];
count[3]++;
printf("-0.01, …Run Code Online (Sandbox Code Playgroud) 我在stackoverflow上查看了很多不同的主题,但到目前为止找不到任何有用的东西:/
所以这是我的问题.我正在写一个文件复制者.在读取文件时已发生此问题.我的测试文档有3行随机文本.所有这三行都应该用字符串数组写出来.问题是只有textdocument的第二行被写入数组,我无法弄清楚原因.已经调试过,但没有让我更进一步.
我知道有一个不同的解决方案,文件复制程序有不同的类等.但我真的想让它与我在这里使用的类一起运行.
String[] array = new String[5];
String datei = "test.txt";
public String[] readfile() throws FileNotFoundException {
FileReader fr = new FileReader(datei);
BufferedReader bf = new BufferedReader(fr);
try {
int i=0;
//String Zeile = bf.readLine();
while(bf.readLine() != null){
array[i] = bf.readLine();
// System.out.println(array[i]); This line is for testing
i++;
}
bf.close();
} catch (IOException e) {
e.printStackTrace();
}
return array;
Run Code Online (Sandbox Code Playgroud) 我为程序编写了一些代码,它给出了我定义为函数的序列的值f(x),但是当我运行它时会出现错误弹出'int' object is not callable".有人知道如何解决问题吗?
def f(x):
if x%2==0:
return x/2
else:
return 3*x+1
limite=int(input("parar en: "))
x=int(input("a1: "))
print(x)
n=1
while n<=limite:
f=f(x)
print(f)
n=n+1
print("fin")
Run Code Online (Sandbox Code Playgroud) while-loop ×10
if-statement ×2
java ×2
python ×2
arrays ×1
c ×1
c++ ×1
control-flow ×1
filereader ×1
filewriter ×1
function ×1
go ×1
greedy ×1
increment ×1
javascript ×1
json ×1
loops ×1
mysql ×1
php ×1
sequence ×1
setinterval ×1
sql ×1
swift ×1
syntax-error ×1
try-catch ×1