小编sre*_*sad的帖子

如果没有无法访问的返回语句,Go代码将无法编译

以下是在Go中查找数字的阶乘的程序:

func factorial(x uint) uint {
    if x == 0 {
        return 1
    }

    return x * (factorial(x - 1))
}
Run Code Online (Sandbox Code Playgroud)

在输入5上调用此函数的输出是120.但是,如果我添加一个else语句,我会收到错误.

func factorial(x uint) uint {
    if x == 0 {
        return 1
    } else {
        return x * (factorial(x - 1))
    }
}
Run Code Online (Sandbox Code Playgroud)

错误: function ends without a return statement

return在最后添加了一个:

func factorial(x uint) uint {
    if x == 0 {
        return 1
    } else {
        return x * (factorial(x - 1))
    }
    fmt.Println("this …
Run Code Online (Sandbox Code Playgroud)

go

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

如何检查文件名是否包含C#中的子字符串

我有一个名为文件的文件夹

  1. myfileone
  2. myfiletwo
  3. myfilethree

如何检查文件"myfilethree"是否存在.

我的意思是除了方法之外还有另一种IsFileExist()方法,即像filename包含子串"三"?

.net c#

11
推荐指数
2
解决办法
3万
查看次数

难以在Java中抛出NoSuchElementException

这是我第一次尝试使用java中的代码双向链接程序:

这是我在双链表中获取迭代器以获取所有项目的实现

public Object next()  {
    if(list.getSize()==0){
     throw new NoSuchElementException();

    }else{ 
        current=current.getNext();
        return current.getItem();
    } 
}
Run Code Online (Sandbox Code Playgroud)

请不要嘲笑我,不管我尝试得到什么

找不到符号:符号类:NoSuchElementException

我尝试创建一个扩展Exception的类NoSuchElementException.java

然后我明白了

未报告的异常NoSuchElementException; 必须被捕获或声明抛出新的NoSuchElementException();

我尝试将代码更改为:

public Object next() throws NoSuchElementException {
Run Code Online (Sandbox Code Playgroud)

然后我明白了

ElementsIterator中的next()无法在java.util.Iterator中实现next(); 重写方法不会抛出NoSuchElementException

任何人都可以指出我错在哪里.如果这还不足以解决此问题,请告诉我.

java exception

7
推荐指数
2
解决办法
3万
查看次数

正弦180的值为1.22465e-16

我想在ios4中实现一个正弦和余弦计算器:

if([operation isEqual:@"sin"]){
    operand = (operand*M_PI/180.0);
    operand=sin(operand);
}
Run Code Online (Sandbox Code Playgroud)

代码为我提供了从0到90的正确答案.

当我给出180的价值时,我会得到1.22465e-16答案.我期待零.

这个小差异来自哪里?

floating-point ios4

3
推荐指数
2
解决办法
2016
查看次数

哈希码功能

我的字符串哈希码函数如下

hashVal=(127*hashVal+key.charAt(i))%16908799
Run Code Online (Sandbox Code Playgroud)

我正在网上跟踪cs61 b讲座,当乔纳森教授关于会发生什么情况时,如果不是1690877,我们会使用一个与127不相对素数的值.我理解他使用127而不是16908799的简单情况.如果它是127的简单倍数怎么办?它如何" 偏向 "哈希值?偏差如何取决于公因子"x"?谁有人建议我的原因?

hashcode

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

学习围棋 - 范围

嗨,我是Go编程语言的新手.

我正在学习http://www.golang-book.com/

在第4章的练习中,有一个关于从华氏温度转换为摄氏温度的问题.

我将答案编码如下

    package main

import "fmt"

func main(){

    fmt.Println("Enter temperature in Farentheit ");

    var input float64

    fmt.Scanf("%f",&input)

    var outpu1 float64 = ( ( (input-32)* (5) ) /9)
    var outpu2 float64=  (input-32) * (5/9)
    var outpu3 float64= (input -32) * 5/9
    var outpu4 float64=  ( (input-32) * (5/9) ) 

    fmt.Println("the temperature in Centigrade is ",outpu1)
    fmt.Println("the temperature in Centigrade is ",outpu2)
    fmt.Println("the temperature in Centigrade is ",outpu3)
    fmt.Println("the temperature in Centigrade is ",outpu4) 
}
Run Code Online (Sandbox Code Playgroud)

输出如下

sreeprasad:projectsInGo sreeprasad$ go …
Run Code Online (Sandbox Code Playgroud)

go

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

执行perl时,'$'转换为'2918 1174 2918'

我有一个吐出html页面的perl.我想使用jquery操作html页面.我已将所有jquery代码放入字符串并将该字符串放入其中

<script type='javascript'> code </script> 
Run Code Online (Sandbox Code Playgroud)

块.但是当我执行perl时,我的所有$符号都被转换为2918 1174 2918.所以如果我的代码$(".className")现在我得到了2918 1174 2918(".className")

有人可以指导我吗?我的代码如下:

 my $str = "<html><head><script type='text/javascript' src='js/top5jquery-1.6.2.min.js'>";
   $str .="<script type='text/javascript'>$('.submitButton').click(function(){ alert('clicked submit button'); });";
   $str .="</head><body><input type='submit' value='submit' />Submitting</body></html>";

my $file_name = "/mainDirectory/myfile";
my $fh;
open ($fh, "> $file_name") or die "Can not open $file_name to write";
print $fh $str;
close($fh);
Run Code Online (Sandbox Code Playgroud)

perl jquery

2
推荐指数
3
解决办法
286
查看次数

使用meteor创建列表

嗨,我正在使用流星创建一个借钱跟踪网站.这是我第一次尝试学习流星js.我尝试在我的js文件中编写以下代码

var lists = new Meteor.Collection("Lists");
Run Code Online (Sandbox Code Playgroud)

但是当我在刷新页面和类型后返回Chrome开发者控制台时

lists
ReferenceError: lists is not defined
get stack: function () { [native code] }
message: "lists is not defined"
set stack: function () { [native code] }
__proto__: Error
Run Code Online (Sandbox Code Playgroud)

有什么我想念的吗?任何人都可以帮助我.

javascript meteor

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

错误:在'stackEmpty'之前预期'=',',',';','asm'或'__attribute__'

此代码用于在C中实现通用堆栈功能.

Code for stack.h
-------------

    typedef struct{
    void *elements;
    int elementSize;
    int logofElementsLength;
    int allocatedLength;

}stack;

bool stackEmpty(const stack *s);
Run Code Online (Sandbox Code Playgroud)

Client.c中的实现代码

bool stackEmpty(const stack *s)
{return (s->logLength==0);
}
Run Code Online (Sandbox Code Playgroud)

错误

error: expected '=', ',', ';', 'asm' or '__attribute__' before 'stackEmpty'
Run Code Online (Sandbox Code Playgroud)

评论

代码编译否则我只在这一行得到错误.显然,错误必须来自这行代码.我在用

gcc -O0 -g3 -Wall -arch i386 -c -fmessage-length=0 -MMD -MP -MF"Client.d" -MT"Client.d" -o"Client.o" "../Client.c"

编译.

我在MAC Snow Leopard OS上运行.我已导入stack.hClient.c和所有其他代码编译并运行正常.任何帮助,将不胜感激.

c compiler-errors

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

标签 统计

go ×2

.net ×1

c ×1

c# ×1

compiler-errors ×1

exception ×1

floating-point ×1

hashcode ×1

ios4 ×1

java ×1

javascript ×1

jquery ×1

meteor ×1

perl ×1