小编hak*_*ata的帖子

构造函数处理异常并使用此关键字Java

我的类有两个构造函数,一个接受File对象,另一个接受一个String对象,我想使用this关键字.实现的函数是带有Fileas参数的函数和带有String将调用的函数this.现在我想在构造函数中检查异常,String但是我得到了错误,那this应该是第一行.如何检查错误然后调用this.

这是我的代码:

public Test (String filename) {
    if (filename == null)
        throw new NullPointerException("The String you entered is null.");
    if (filename.isEmpty())
        throw new IllegalArgumentException("The String you entered is empty.");

    this(new File(filename)); // error
}

public Test (File f) {
    /* implementation here */
}
Run Code Online (Sandbox Code Playgroud)

这是确切的错误: Constructor call must be the first statement in a constructor

java constructor exception this

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

标准ml中的最大整数和最小整数

我想使用ml的最大整数和最小整数,但我不能,我从库中看到它的int类型选项,我该如何使用它?我在这里看到它http://www.standardml.org/Basis/integer.html#SIG:INTEGER.minInt:VAL

我想用它来制作max和min函数,每个方法都取一个整数列表,我必须分别返回max和min.

我尝试过以下代码,但它们没有用:

- fun max x = 
=   foldr (fn (a, b) => if a > b then a else b) INTEGER.minInt x;

- fun max x = 
=   foldr (fn (a, b) => if a > b then a else b) minInt x;

- fun max x = 
=   foldr (fn (a, b) => if a > b then a else b) Int.minInt x;
Run Code Online (Sandbox Code Playgroud)

有人知道如何使用它们吗?

types max sml min option

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

指令集仿真器指南

我有兴趣编写像gameboy和其他手持控制台这样的模拟器,但我读到的第一步是模拟指令集.我发现这里有一个链接说初学者模仿Commodore 64 8位微处理器,事情是我不知道有关模拟指令集的事情.我知道mips指令集,所以我认为我可以管理理解其他指令集,但问题在于它是什么意思通过模拟它们?

注意:如果有人可以为我提供初学者指令集仿真的分步指南,我将非常感激.

注意#2:我打算用C写.

注意#3:这是我第一次尝试学习整个仿真的东西.

谢谢

编辑:我发现这个网站是一个详细的分步指南,编写一个看起来很有希望的模拟器.我将开始阅读它,并希望它也能帮助那些正在研究模拟器的人.

仿真器101

emulation instruction-set instructions microprocessors

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

使用Javascript更改td元素文本

我正在为html文件编写代码,该代码将显示36000个掷骰子的每个骰子总数.我编写代码,一切似乎都很好,我打印了每个总和的数字,我得到了数字,但是当我尝试将它们放在td元素中时,我在表中看不到任何内容.我在stackoverflow和谷歌上搜索了所有相同的事情,但它没有用.这是我的代码:

<!DOCTYPE html>

<html>
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <script type="text/javascript">
            <!--

            /*

                Position #0 : Sum of Dices = 2
                Position #1 : Sum of Dices = 3
                Position #2 : Sum of Dices = 4
                Position #3 : Sum of Dices = 5
                Position #4 : Sum of Dices = 6
                Position #5 : Sum of Dices = 7
                Position #6 : Sum of Dices = 8
                Position #7 : Sum of Dices = 9
                Position #8 : Sum …
Run Code Online (Sandbox Code Playgroud)

html javascript html-table

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

方法中的java可选参数

我想创建一个方法,需要1个必需参数和1个可选参数,但我发现如何通过在参数(int ... b)中创建一个可选数组,但这是一个数组,我想制作它只是这个值为null或用户输入它,我可以通过制作两个相同名称的方法,但一个具有单个参数和一个具有2个参数,但是它可以只使用一个方法吗?

谢谢

java arrays parameters methods null

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

如何检查字符串是否由PHP中的整数组成

我正在编写PHP代码来验证用户输入的一些数据,其中一个是整数,我曾经$_REQUEST["age"]得到它,当我检查这个值是否为整数时gettype($_REQUEST["age"] == "integer",is_int($_REQUEST["age"])两者都给我假,但是当我使用时is_numeric($_REQUEST["age"])是给出我是真的.我想检查参数的值是否是整数,我是正确使用前2个函数还是我遗漏了什么?

Thakns

注意:我试图输出gettype($_REQUEST["age"])它给我string

php

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

无法将nullptr返回到我的类C++

在我班上的方法中,我正在检查值是否为0才能返回nullptr,但我似乎无法做到这一点.

Complex Complex::sqrt(const Complex& cmplx) {
    if(cmplx._imag == 0)
        return nullptr;

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

我得到的错误是: could not convert 'nullptr' from 'std::nullptr_t' to 'Complex'

我现在意识到,这nullptr是指针,但是,我的对象不是指针,有没有办法让我将它设置为null或类似的东西?

c++ null nullptr

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

多项式方程标准毫升

我正在尝试创建一个函数来解决标准 ML 中的单变量多项式方程,但它一直给我错误。

代码如下

(* Eval Function *)
- fun eval (x::xs, a:real):real = 
    let
        val v = x (* The first element, since its not multiplied by anything *)
        val count = 1 (* We start counting from the second element *)
    in
        v + elms(xs, a, count)
    end;

(* Helper Function*)
- fun pow (base:real, 0) = 1.0
    | pow (base:real, exp:int):real = base * pow(base, exp - 1);

(* A function that solves the equation except the …
Run Code Online (Sandbox Code Playgroud)

standards functional-programming eval sml

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

Typedef一个位域变量

我想要一个1位整数的typedef,所以我虽然这样typedef int:1 FLAG;但是我遇到错误,有没有办法可以这样做?谢谢

c typedef bit-fields

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

添加到相同的php页面并等待用户输入

我试图从用户那里获得输入,然后当他按下提交时,它将在数据库中进行查询并将结果返回到表中.然而,我的代码似乎没有等待,因为它会自动执行我保存查询结果的var为false的场景.我试图在同一页面上执行此操作,因为如果我将数据发送到另一个页面,它可以工作,但我想最小化我正在使用的文件数量.

这是我的代码:

<!doctype html>

<html>
    <head>
        <meta charset="UTF-8">
        <title>View a Faculty Member</title>
        <style type="text/css">
            .block {
                display:block;
                margin-top:3px;
            }
        </style>
    </head>

    <body>
        <h1>View a faculty member:</h1>

        <form action="" method="post">
            <label class="block">Please Enter ID: <input type="text" placeholder="ie. 12345" maxlength="30" size="30" name="id"></label>

            <input class="block" type="submit" name="submit" value="Get Faculty Member">
        </form>

        <hr/>

        <?php

        // 1- get the id
        // 2- construct query in string
        // 3- connect to db
        // 4- execute the query
        // 5- put the result in a var
        // …
Run Code Online (Sandbox Code Playgroud)

html php mysql pdo

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