小编Woo*_*ble的帖子

生成一个整数并将其用作字符串数组的索引

我最近开始使用android编程,只掌握java的基础知识.我的代码遇到了问题,我的目标是在单击按钮后显示已经在我的数组中编程的随机选择的文本(onclick事件).

public void magicbegins() //
{
    int min = 0;
    int max = 3;
    Random r = new Random();
    int rand = r.nextInt(max - min + 1) + min;
    //generating random number from 0 to 3 to use as index in later event
    String[] magictext = {"yes", "no", "maybe"};

    TextView text = (TextView) findViewById(R.id.textView1);
    //using the generated number as index for programmed string array
    text.setText(magictext[rand]);
}
Run Code Online (Sandbox Code Playgroud)

如果任何情况下不建议使用此代码,那么是否有人会提供一个示例脚本,该脚本与我的目标至少相似?

java android

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

在std :: string中找到最后一个字符错误:表达式:字符串下标超出范围

因此,这会在执行时返回错误,调试器中不会显示错误.

调试断言失败了!

表达式:字符串下标超出范围.

有关程序如何解决断言失败的信息,请参阅有关断言的visual c ++文档.

int main()
{
// declaring variables
string input = "";
int firstChar;

// process:
cout << "Please enter a valid sentence (with spaces):\n>";
getline(cin, input);

cout << "first char is " + input[0] << endl << endl;
firstChar = input.length();
cout << "last char is " + input[firstChar];

// stop and return success
getchar();
return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++

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

我可以在html文本框中运行java代码吗?

我正在写一个网页,我在其中放置一个html输入类型="textarea",其中用户将编写他们的Java代码,并在提交时将返回该java代码的输出.我可以使用jsp吗?如果不是那么其他方式是什么.

html java jsp

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

带冒号(:)分隔数据的fscanf

fscanf这条数据怎么样?数据和分隔符之间没有空行':'

VS1234567890654327:Rob Fordfirst:001:200
VS1234567890654312:Steven Harper:200:010
Run Code Online (Sandbox Code Playgroud)

我的代码

while(3==fscanf(filename, "????", &string[size], &name[size], &number1[size], &number2[size])) {
    //printf("%s - %s - %.3d - %.3d", string[size], name[size], number1[size], number2[size]));
    size++;
}
Run Code Online (Sandbox Code Playgroud)

c field file scanf

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

使用C中索引大于50的数组时进行核心转储

在编写带指针和数组的简单程序时,我遇到了一些麻烦.目标是使用指针将值128插入到数组的512个索引中.问题是,如果我使用超过50个索引,我将获得核心转储.我错过了什么或者是环境限制吗?是malloc()需要还是应该在其他地方定义数组?

#include <stdio.h>
#include <stdarg.h>
#define MAX 512

int main(void){
    int  i, *p, a[MAX];
    i = 0;
    p = &a[0];
    for (i=0 ; i <= MAX; i++){
        *(p+i) = 128;
    }
    printf("First value  %d last value of pointer  %d\n", *p, *(p+(MAX-1)) );

}
Run Code Online (Sandbox Code Playgroud)

c arrays pointers

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

for 在“列表的第一个元素”范围内循环

我有一个具有以下结构的列表:

a = [[1,'a'], [2,'b'], [3,'c']]
Run Code Online (Sandbox Code Playgroud)

我想在每个子列表中创建第一个元素的范围,而不进行第二个 for 循环。我在想这样的事情:

for i in a[][0]:
    print i
Run Code Online (Sandbox Code Playgroud)

然而,上面最后的代码不起作用(SyntaxError: invalid syntax)。知道是否可以在 Python 中做到这一点吗?

编辑:

我想通过上述循环得到的输出是:

1
2
3
Run Code Online (Sandbox Code Playgroud)

并不是

1
a
Run Code Online (Sandbox Code Playgroud)

python for-loop list

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

什么'void(*return_socket)(void*closure);' 意思?

我正在浏览XCB源代码,我发现了这个奇怪的struct成员:

void (*return_socket)(void *closure);
Run Code Online (Sandbox Code Playgroud)

那是什么意思?写这个的另一种方式是什么?

c syntax xcb

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

从嵌套对象树获取路径

我目前遇到的一个问题是,当我开始时似乎并不难为我解决,但我现在卡住了几个小时,所以我们走了:

给定这个对象数组:

groups = [
  {
    name: 'Custard apple',
    slug: 'custard-apple',
    children: [
      {
        name: 'Vanilla',
        slug: 'vanilla',
        children: [
          {
            name: 'Strawberry',
            slug: 'strawberry',
            children: []
          }, {
            name: 'Pineapple',
            slug: 'pineapple',
            children: []
          }
        ]
      }, {
        name: 'Chocolate',
        slug: 'chocolate',
        children: []
      }
    ]
  }, {
    name: 'Raspberry',
    slug: 'raspberry',
    children: []
  }, {
    name: 'Lemon',
    slug: 'lemon',
    children: [
      {
        name: 'Orange',
        slug: 'orange',
        children: [
          {
            name: 'Coconut',
            slug: 'coconut',
            children: []
          }
        ]
      }, …
Run Code Online (Sandbox Code Playgroud)

javascript recursion coffeescript

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

这是什么样的格式/语言O:8:"stdClass":5 :? (xml,json)需要在python中提取值.

这是价值:

   O:8:"stdClass":5:
{s:11:"origination";O:8:"stdClass":2:
    {s:8:"username";s:9:"Prod";s:8:"password";s:8:"vi5";}
    s:9:"serviceId";s:10:"9202501358";s:8:"elements";a:1:
    {i:0;s:4:"3260";}s:11:"serviceKeys";a:6:
    {i:0;O:8:"stdClass":2:
        {s:2:"id";i:1;s:5:"value";s:10:"2102799679";}i:1;O:8:"stdClass":2:
        {s:2:"id";i:1395;s:5:"value";s:0:"";}i:2;O:8:"stdClass":2:
        {s:2:"id";i:1390;s:5:"value";s:0:"";}i:3;O:8:"stdClass":2:
        {s:2:"id";i:1391;s:5:"value";s:0:"";}i:4;O:8:"stdClass":2:
        {s:2:"id";i:1392;s:5:"value";s:0:"";}i:5;O:8:"stdClass":2:
        {s:2:"id";i:1393;s:5:"value";s:0:"";}}s:7:"transId";s:1:"1";}
Run Code Online (Sandbox Code Playgroud)

我正在尝试提取其存储在mysql中的值为" data "的变量,

我不确定这是不是json,但对于json来说,它会像......没有" ; "

{"employees":[
    {"firstName":"John", "lastName":"Doe"}, 
    {"firstName":"Anna", "lastName":"Smith"},
    {"firstName":"Peter", "lastName":"Jones"}
]}
Run Code Online (Sandbox Code Playgroud)

如何使用python提取这个?我通常会看到使用xpath的xml: etree.XPath帮助提取值,但这种格式对我来说是新的.无法弄明白从哪里开始.一些建议将不胜感激.

python

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

比较python中的字符串

如何比较两个字符串和字符值列表

l=['s','t','a','k','','o','v','e','r']
s='stack over'
Run Code Online (Sandbox Code Playgroud)

如何比较内容(列表和s).如果两者都相等则必须返回"零",如果一个大于其他,则返回正数小于其他负值我想比较上面列表'l'和字符串's'请告诉我如何做用python代码..

python

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

标签 统计

c ×3

python ×3

java ×2

android ×1

arrays ×1

c++ ×1

coffeescript ×1

field ×1

file ×1

for-loop ×1

html ×1

javascript ×1

jsp ×1

list ×1

pointers ×1

recursion ×1

scanf ×1

syntax ×1

xcb ×1