小编Rei*_*ica的帖子

输出窗口卡在黑屏上

#include<stdio.h>

int main()
{
    static int x;
    if(x == 10)
    printf("\n thanks...");
    x++;
    return (x=main());
}
Run Code Online (Sandbox Code Playgroud)

在运行程序时,它会卡在输出上:

谢谢...

这里有什么问题?

c recursion tail-recursion

1
推荐指数
1
解决办法
153
查看次数

如何使用json回显数组?

我的代码似乎没有返回JSON $_GET['fruitVariety'],任何想法为什么?我的数据库设置正确.

这就像json_encode只能回显1个数组.

$rows = array();

if(isset($_GET['fruitName'])) {
    $stmt = $pdo->prepare("SELECT DISTINCT variety FROM fruit WHERE name = ? ORDER BY variety");
    $stmt->execute(array($_GET['fruitName']));
    $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
}

if(isset($_GET['fruitVariety'] )) {
    $stmt = $pdo->prepare("SELECT DISTINCT fruittype FROM fruit WHERE name = ? ORDER BY fruittype");
    $stmt->execute(array($_GET['fruitVariety']));
    $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
}

echo json_encode($rows);
Run Code Online (Sandbox Code Playgroud)

php mysql json pdo

1
推荐指数
1
解决办法
734
查看次数

当我接受矩阵的第一个值时,分段错误

如果我运行我的程序,当我输入矩阵的维度时,在输入矩阵的第一个值后,控制台会写出:分段错误

例如:

4

3
Run Code Online (Sandbox Code Playgroud)

分段错误进程返回139(0x8B)

void inMatrix(int n, double **matrix)
{
    int j, i;
    for (i = 0; i < n; i++)
    {
        for (j= 0; j < n; j++)
        {
            scanf("%lf", &matrix[i][j]);
        }
    }
}

void inVector(double *vektor, int n)
{
    int k;
    for (k = 0; k < n; k++)
    {
        scanf("%lf", &vektor[k]);
    }
}

int main()
{
    int n;
    // read dimension of matrix and value
    scanf("%d", &n);

    //matrix
    double** matrix = (double **) calloc(n, sizeof …
Run Code Online (Sandbox Code Playgroud)

c segmentation-fault

1
推荐指数
1
解决办法
262
查看次数

如果我覆盖.equals(),即使我不使用HashMap,我是否需要覆盖.hashCode()?

如果我选择永远不将我的对象存储在集合中,是否需要覆盖哈希码或者我的对象可以使用相同的哈希码?表现好坏?

java

1
推荐指数
2
解决办法
166
查看次数

固定大小的数组不固定

我正在使用SRand/Rand生成一个随机数组.数组大小取决于提示用户输入的数字.基本上,如果用户输入的大小为9,则数组应为9个数字.然后应使用带有参数的rand()填充此数组,以使数组值保持小于18.问题是,有时会生成随机大小的数组.也许每运行一次该程序的第4或第5次,该数组可能是12-14个数字.我无法看到我的代码出现问题.我在下面添加了一个片段.有人对此有所了解吗?

int main(void)
{
    int N;
    int i;

    printf("Please enter a number\n");
    scanf("%d", &N);

    srand (time(NULL));
    int numarray[N];  
    for(i=1; i<numarray[N]; i++)
    {
        numarray[i]=rand()%21;
        printf("%d\n", numarray[i]);
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c arrays random

1
推荐指数
1
解决办法
227
查看次数

为什么我在将字符串转换为int数组时得到一个空指针?

我的主要方法:

public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    String string1;
    string1 = input.next();

    LargeInteger firstInt = new LargeInteger(string1);

    System.out.printf("First integer: %s \n", firstInt.display());
}
Run Code Online (Sandbox Code Playgroud)

LargeInteger类:

public class LargeInteger {

    private int[] intArray;

    //convert the strings to array
    public LargeInteger(String s) {
        for (int i = 0; i < s.length(); i++) {
            intArray[i] = Character.digit(s.charAt(i), 10); // in base 10
        }
    }

    //display the strings
    public String display() {
        String result = "";

        for (int i = …
Run Code Online (Sandbox Code Playgroud)

java

1
推荐指数
1
解决办法
262
查看次数

python中的可变打印

我是Python的新手,我正在尝试声明一个变量并打印它的值.

这是我的代码:

#!C:\Python32\python.exe
import sys
import os
import cgi
import cgitb
cgitb.enable()
a = 5
print(a)-------------------------> My doubt is in this line
Run Code Online (Sandbox Code Playgroud)

但是我的一个朋友写道print a.在他的Python中,它正在打印该值,但在我的情况下,它显示为"无效语法".为什么会这样?

python

1
推荐指数
1
解决办法
158
查看次数

executor.shutDownNow()不会阻止内部方法执行

我创建了一个未来任务并将其提交给Executor.在run()方法中,我创建了placementPlanner的对象.此类中的方法调用其他类.但是,当我调用executor.shutDownNow()时,调用的内部方法不会停止执行.如何调用我杀死所有子线程并停止调用方法.代码如下.

static List<Result> invokePlacementPlannerWithTimeout(int timeoutSecs,
        final String requestType, final RequestMap requestMap,
        final ReleaseMap releaseMap, final SysConfig systemConfig,
        final Request request, final SigmaBlade hostData,
        final ServiceLevelData serviceLevelData,
        final List<Service> serviceList, final String transactionID) throws IOException {

    /**
     * Object of ExecutorService interface used for timed execution of Placement
     * Planner.
     */
    ExecutorService executor = Executors.newFixedThreadPool(1);
    /**
     * Creating a final List of Result type.
     */
    final List<Result> resultList = new ArrayList<Result>();
    /**
     * set the executor thread working
     */
    Future<?> future …
Run Code Online (Sandbox Code Playgroud)

java

1
推荐指数
1
解决办法
1101
查看次数

如何检查字符串是否包含法语字母?

在Java中,我们如何检查一个字符串是否包含法语字母?

java

1
推荐指数
1
解决办法
3686
查看次数

为什么我得到"为foreach提供的无效参数"?

我正在我的数据库中创建一个搜索,当我使用foreach构造为我的结果回应时,我得到"为foreach提供的无效参数......".我不明白的是为什么会出现这个错误,因为包含我的错误的foreach工作正常.

if (empty($errors)){
    $results = search_results($keywords);
    $results_num = count($results);

    foreach ($results as $result){
        echo '<p> <strong>', $result['TITLE'], '</strong> </p>';
    }
} else {
    foreach($errors as $error){
        echo $error, '</br>';
    }
}
Run Code Online (Sandbox Code Playgroud)

search_results函数中关注的部分就是这个

$results = "SELECT TITLE FROM occupationalinfo WHERE $where"; 
$results_num = ($results = mysql_query($results)) ? mysql_num_rows($results): 0;

if ($results_num === 0){
    return false;
}else{
    while ($results_row = mysql_fetch_assoc($results)) {
        $returned_results[] = array(
            'title' => $results_row['TITLE']
        );      
    }
}
Run Code Online (Sandbox Code Playgroud)

我仍然是编程的新手,所以我理解是否有一些我可能错过或者不太了解的东西.我非常感谢任何提示或建设性的批评.

php arrays foreach

0
推荐指数
1
解决办法
75
查看次数

标签 统计

java ×4

c ×3

arrays ×2

php ×2

foreach ×1

json ×1

mysql ×1

pdo ×1

python ×1

random ×1

recursion ×1

segmentation-fault ×1

tail-recursion ×1