l******r 发帖数: 99 | 1 what if "value is null"?
then newvalue = value.replace(....) will return a NullPointerException |
|
s*****r 发帖数: 773 | 2 这里的2, 3, 4 种情况都不算边界情况吧, 都可以同时解决.
请看看我写的这个code如何, 我没有考虑溢出的问题, 请问溢出的情况如何考虑?
int reverseint(int value) {
unsigned sign = 1;
if( value < 0) {
value = -value;
sign = -1;
}
int newvalue = 0;
while(value > 0) {
newvalue= newvalue*10 + value%10;
value = value/10;
}
newvalue *= sign;
return newvalue;
} |
|
s******n 发帖数: 3946 | 3 要那么复杂么,只要判断前一个数和后一个数是否翻转了"-"即可
int atoi(char* str) {
bool neg = false;
if (*str=="-") {
str++;
neg = true;
} else if (*str=="+")
str++;
int value = 0;
while (*str) {
int digit = *str-'0';
if (digit>9 || digit<0) throw "error";
int newvalue = value*10 + neg?(-digit):digit;
if (value>0 && newvalue<0 || value<0 && newvalue>0) throw "overflow";
value = newvalue;
str++;
}
return value;
}
} |
|
h**********c 发帖数: 4120 | 4 把newValue 用花扩号shadow 一下
def newValue =12
...
// very long block
..
{
def newValue = 24
}
// Use newValue here |
|
x*****p 发帖数: 1707 | 5 Java is definitely pass by reference. However, String is immutable, that is
why you can not change its value by reference. If you want to output "
Goodbye", you can use reflection. The code is below.
private void mutate(Object str) {
try {
Field field = String.class.getDeclaredField("value");
field.setAccessible(true);
char[] newValue = "Goodbye".toCharArray();
field.set(str, newValue);
Field field2 = String.class.getDeclaredField("count");
field2.setAccessible(tr... 阅读全帖 |
|
L*******g 发帖数: 913 | 6 【 以下文字转载自 Programming 讨论区 】
发信人: LocalKing (M-M-M-Monster), 信区: Programming
标 题: 请教编一个有mark/unmark功能的网页按钮 php/ajax?
发信站: BBS 未名空间站 (Tue Mar 27 14:23:23 2012, 美东)
我有一个html表格,每行都想有一个小标记,比如default是显示A,鼠标点一下A它就
变成B,再点一下B它有变成A,同时在一个数据文件里记录当时的值,而又不要刷新网
页其它的内容。
网上大致搜了一下,好像php+ajax可以满足需要,我试着学w3schools的教程写了一点
,但是总不对:
index.htm:
-------------
...
|
|