堆地址是由堆地址共享的吗?(Is stack address shared by Heap addresses?)
我读过在大多数操作系统上,内存中的地址从最高到最低。 所以我想知道堆,堆栈和全局内存是否都属于相同的顺序..?
如果我创建...
pointerType* pointer = new pointerType //creates memory address 0xffffff
然后在堆栈上创建一个本地变量
localObject object
localObjects的地址是0xfffffe
或者是堆和堆栈排序完全不同。
I read On most operating systems, the addresses in memory starts from highest to lowest. So I am wondering if the heap, stack, and global memory all fall under the same ordering..?
If I created...
pointerType* pointer = new pointerType //creates memory address 0xffffff
And then created a local varible on the stack
localObject object
would localObjects address be 0xfffffe
Or is heap and stack ordering completely different.
原文:https://stackoverflow.com/questions/3070841
最满意答案
在每个actionPerformed调用期间,您将遍历整个列表。 这里:
while(x < questions.length){ problem.setText(questions[x]); response[y] = String.format("%s",event.getActionCommand()); input.setText("Answer goes here"); x++; y++; }
因此,当文本实际再次显示时,您已将其设置为每个不同的问题,但是停止使用最后一个问题,这就是用户实际看到的内容。 每次执行操作时,您只想将文本更改为下一个问题。
您需要保留某种计数器,以便您可以通过
actionPerformed
方法访问您所处的问题另外,如评论中所述,您需要更改结果检查以使用equals方法。 使用
==
符号无法比较字符串,因为对于Strings==
比较每个String
对象指向的引用,而不是String
对象的值if(response[z].equals(answers[z])) result++;
During each actionPerformed call you cycle through the whole list. Here:
while(x < questions.length){ problem.setText(questions[x]); response[y] = String.format("%s",event.getActionCommand()); input.setText("Answer goes here"); x++; y++; }
So by the time the text is actually displayed again, you have set to it to each different question, but stop with the last one and that is what the user actually sees. You only want to change the text once, to the next question, everytime an action is performed.
You'll need to keep some sort of counter for which question you are on that can be accessed by the
actionPerformed
methodAlso, as mentioned in the comments, you will want to change your result checking to use the equals method. Strings can't be compared using the
==
sign because for Strings==
compares the reference eachString
object is pointing to, not the value of theString
objectif(response[z].equals(answers[z])) result++;
相关问答
更多-
当用户点击时,如何阻止我的文本在数组中循环?(How do I stop my text from cycling through the array when the user clicks?)[2023-10-28]
您应该将单词拾取逻辑移出绘图功能。 只需在进入循环之前选择一个单词,然后将该单词传递给绘制函数,该函数只能实际绘制一些东西。 你可以这样做: var canvas; var context; var texts = []; var timer; var textSayings = ['Cool!', 'Nice!', 'Awesome!', 'Wow!', 'Whoa!', 'Super!', 'Woohoo!', 'Yay!', 'Yeah!'] function init() { c ... -
不在jQuery中循环(Not Cycling Through in jQuery)[2023-04-14]
必须在这方面与mkoryak站在一起。 代码过度复杂化了这个问题。 这就是我将如何做到的(当然,这完全没有经过测试): var fade_time = 1000; var wait_time = 15000; var curr = 0; var last = 41; var bg = $("#background"); function do_fade() { curr++; if (curr > last) { curr = 1; } bg.fadeOut ... -
Java通过对象循环(Java cycling through objects)[2023-08-05]
如果我正确地理解了这个问题,每个玩家都有一个名字,11个分数和一个总数。 你似乎在问如何迭代玩家名单,并使总数等于11分的总和。 更常用的(用OO语言)方法就是确保总数总是等于11分的总和。 (这被称为“封装”,并且是所有面向对象编程背后的基本思想。)这很容易实现(为了便于编程,我将分数放在一个数组中): public class Player { private String name ; private int[] scores ; private int total ; ... -
您的代码大致如下所示: fetch categories if(categories not empty) { foreach(category) { set $bgcolor and $userId (has no effect) } get query results for the last $userID and set $totalEmailEarnAmount1 if(categories not empty) { foreach(category) { ...
-
在每个actionPerformed调用期间,您将遍历整个列表。 这里: while(x < questions.length){ problem.setText(questions[x]); response[y] = String.format("%s",event.getActionCommand()); input.setText("Answer goes here"); x++; y++; } 因此,当 ...
-
不,#each只执行一个块,它不会累积任何数据。 [1, 2, 3].each{ |n| "Link to item #{n}" } #=> [1, 2, 3] 您有两个选项,使用map来累积数据: [1, 2, 3].map{ |n| "Link to item #{n}" }.join("\n") #=> "Link to item 1\nLink to item 2\nLink to item 3" 或直接在块中输出: [1, 2, 3].each{ |n| puts "Link to item ...
-
单击循环数组(Cycling an array on click)[2022-02-23]
我想你需要这样的东西: var start = 0; var arr = [ a,b,c,d,e,f,g,h,i,j,k,l]; function nextChunk(howMany) { var result = []; while (howMany--) { result.push(arr[start]); start = (start + 1) % arr.length; } return result; } I think you ... -
我会将元素转换为[String:AnyObject] 就像是 if let jsonResults = jsonResults as? [[String: AnyObject]] { for element in jsonResults { //Do stuff } } I would cast Element to [String:AnyObject] ...
-
在处理二维数组时,通过列循环或循环遍历行(Cycling through columns vs cycling through rows when working with 2D arrays)[2022-04-22]
行/列是对称/可互换的,正如您所说,“计算机不关心”。 话虽如此,为什么你认为“让指针数组是水平的,然后每个数组可以从该水平线上的点下降是最合理的”? 我会想到另一种方式。 我会发现它更容易“可视化”水平对象的行(毕竟,我们是水平写的(比如说,一个字符数组)),而行/行是从上到下(比如数组)。 我认为代码比你的建议更自然(对我来说)。 关键是,我们都有不同的想法,而在一天结束时,ROWS / COLUMNS只是变量,可以很容易地写成X / Y或V / H或W / H或其他。 Rows/columns are ... -
增加要包含的值的常用技巧是使用%运算符。 对于递减,您只需强制它并检查负值: var mediaSizes = ['xs','md','lg']; var media = 0; $scope.mediaDisplay = mediaSizes[media]; var changeMedia = function(direction) { if (direction === 'up') { media = ++media % mediaSizes.lengt ...