所以我有这个代码:
#include <stdio.h>
int arraySum (int *a, int n);
int main(void){
int values[3] = {1, 2, 3};
printf("The sum is %i\n", arraySum(values, 3));
return 0;
}
int arraySum(int *a, int n){
int sum = 0;
int arrayEnd = *a + n;
for ( ; *a < arrayEnd; *a++)
sum += *a;
return sum;
}
Run Code Online (Sandbox Code Playgroud)
出于某种原因,它输出:
roman@lmde64 ~/Dropbox/Practice $ gcc practice.c
roman@lmde64 ~/Dropbox/Practice $ ./a.out
The sum is -421028781
roman@lmde64 ~/Dropbox/Practice $ ./a.out
The sum is -362865581
roman@lmde64 ~/Dropbox/Practice $ ./a.out …
Run Code Online (Sandbox Code Playgroud) 所以我有一个字符串:
天使爱美丽
以字节为单位 b'ame\xcc\x81lie'
在utf-8中,角色结合了前一个角色的重音符号http://www.fileformat.info/info/unicode/char/0301/index.htm
u'ame\u0301lie'
当我这样做:'amélie'.title()在那个字符串上,我得到'AméLie',这对我来说毫无意义.
我知道我可以做一个解决方法,但这是预期的行为还是一个错误?我希望"l"不会被大写.
另一个实验:
In [1]: [ord(c) for c in 'ame?lie'.title()]
Out[1]: [65, 109, 101, 769, 76, 105, 101]
In [2]: [ord(c) for c in 'ame?lie']
Out[2]: [97, 109, 101, 769, 108, 105, 101]
Run Code Online (Sandbox Code Playgroud) 我正在使用python shell来弄清楚print命令在python中是如何工作的.
当我输入
打印01
1
打印010
8
打印0100
64
打印030
24
这里发生了什么?它只是基数2吗?为什么第二个位置的"一个"打印为8?如果它是二进制的,它不应该是2吗?
在这个程序中,内循环生成100个随机数,然后在随机数为7时停止生成它们.外循环重复内循环100次.
为什么我的外循环不能重做内循环?
似乎它只做过一次.
package test;
public class Loops {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int i = 0;
int sum = 0;
int counter = 0;
String randomNumberList = " ";
int c = 0;
while (c != 100){
while (i != 7) {
i = (int) (101 * Math.random());
sum += i;
++counter;
randomNumberList += " " + i;
}
System.out.print("\n loop repeated" + counter+ " times and …
Run Code Online (Sandbox Code Playgroud) 哪一组更"随机"?
Math.random()用于Java或随机用于Mathematica?Java是蓝色的,Mathematica是红色的.
数字从0到50(51?)
编辑:这是在Mathematica中生成的直方图.
Java源码(丑陋)
public static void main(String[] args) {
// TODO Auto-generated method stub
int i = 0;
int sum = 0;
int counter = 0;
String randomNumberList = " ";
int c = 0;
while (c != 50){
while (i != 7) {
i = (int) (51 * Math.random());
sum += i;
++counter;
randomNumberList += " " + i;
}
i = 0;
System.out.print("\n" + randomNumberList);
++c;
}
}
Run Code Online (Sandbox Code Playgroud)
Mathematica源码(output.txt是来自Java的转储)
dataset = ReadList["~/Desktop/output.txt", Number]
dataset2 = RandomReal …
Run Code Online (Sandbox Code Playgroud) java ×2
python ×2
arrays ×1
binary ×1
c ×1
loops ×1
pointers ×1
python-3.x ×1
random ×1
while-loop ×1