我一直试图解决这个问题,app.js会返回"超出最大调用堆栈大小"在我记录" Debug:3"之后。我是Javascript的新手,所以我不确定我是否创建了自称在循环中的函数。这是运行的函数并导致错误。
import javax.swing.*;
public class Main {
public static void main(String[] args)
{
int i;
int n; //here is your number (say 20) and you need all primes below 20
int number; // it will loop through all numbers between 2 to n
boolean nPrime=true;
n = Integer.parseInt(JOptionPane.showInputDialog("Entrer un numero"));
for ( number = 2 ; number <= n ; ++number ) // for outer
{
for (i = 2; i < number; i++) //for inner
/*from here it is simply your code which checks every number
for primeness, BTW you need to check for only upto
square_root(number) so change your code to i*i < number, I
didn't changed it just to make it as similar to yours as
possible
*/
{
if (number % i == 0)
{
nPrime = false;
}
}//for inner closed
if (nPrime)
{
System.out.println("Le numero " + number + " est prime");
}
else
System.out.println("Le numero " + number + " n'est pas prime");
//if you need only primes then remove this else part
nPrime=true;
}//for outer closed
}// main() closed
}//class closed
以下是调用sendNewUserPackage()的方法:
function sendNewUserPackage(node) {
console.log("Debug: 00");///////////////////////////////
for (var i in SOCKET_LIST) {
console.log("Debug: 01");///////////////////////////////
var s = SOCKET_LIST[i];
if (node === 1) {
for (var n in Node1.NODE_PLAYERS) {
console.log("Debug: 02");///////////////////////////////
var pl = Node1.NODE_PLAYERS[n];
if (s.id === pl.id) {
console.log("Debug: 03");///////////////////////////////Code never reaches Debug: 5 at the end of the function
s.emit('newUserPackage', Node1.NODE_PLAYERS);
}
}
}
else if (node === 2) {
console.log("Debug: 04");///////////////////////////////
for (var n in Node2.NODE_PLAYERS) {
var pl = Node2.NODE_PLAYERS[n];
if (s.id === pl.id) {
s.emit('newUserPackage', Node2.NODE_PLAYERS);
}
}
}
else if (node === 3) {
for (var n in Node3.NODE_PLAYERS) {
var pl = Node3.NODE_PLAYERS[n];
if (s.id === pl.id) {
s.emit('newUserPackage', Node3.NODE_PLAYERS);
}
}
}
}
console.log("Debug: 05");///////////////////////////////
}
function sendClientMessage(socket, message) {
socket.emit('message', message);
}
令我困惑的是每个&#34; Debug:num&#34;被调用的只在控制台中显示一次。所以我认为这意味着这两个函数都不会被调用多次。还有别的东西可以造成它吗?
非常感谢帮助!