小编Kif*_*sif的帖子

你好,没有主要方法的世界(由Horstmann提供)

Core Java第7版中的Horstmann写道,可以显示Hello,没有main方法的世界.它是这样完成的:

public class Hello{
    static{
        System.out.println("Hello, world");
    }
}
Run Code Online (Sandbox Code Playgroud)

他说,首先你好,世界将被写入.只有这样您才会收到错误消息.

我用

java version "1.7.0_21"
Java(TM) SE Runtime Environment (build 1.7.0_21-b11)
Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)
Run Code Online (Sandbox Code Playgroud)

我没有对此进行建模.它已经修好了吗?

java

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

基准Python程序

我是Python的新手.这是我的第一个解释语言.到目前为止,我曾经学过Java.因此,当Java程序第一次运行时,它比下一次运行速度慢.reasi是缓存.

import time

def procedure():
    time.sleep(2.5)

# measure process time
t0 = time.clock()
procedure()
print (time.clock() - t0), "seconds process time"
Run Code Online (Sandbox Code Playgroud)

我试了好几次.结果总是相等的.所以,我是对的,没有cashe干扰,基准测试非常可靠吗?

python python-3.x

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

用于模拟开关操作器的dict

在我的教科书中,我读到新手需要一些时间来识别这种结构:

choice = 'ham'
print ({
    'spam': 1.25, 
    'ham': 1.99,
    'eggs': 0.99,
    'bacon': 1.10
}[choice])
Run Code Online (Sandbox Code Playgroud)

结果如下:

The result is 1.99 
Run Code Online (Sandbox Code Playgroud)

说实话,我甚至无法抓住结的尾巴,无法解开它.你可以向我澄清一下吗?

python python-3.x

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

Python 3中字典生成器的文档在哪里?

我是说这个:

>>> d = {a : a ** 2 for a in range(7)}
>>> d
{0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36}
Run Code Online (Sandbox Code Playgroud)

我设法找到这些资源:

这些似乎只是教程; 我想在文档本身中找到它.

python dictionary

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

Python 3:有些反转if语句

在我的教科书中,我遇到了这个例子:

lower = (lambda x, y: x if x < y else y)
print(lower ('bb','aa'))
Run Code Online (Sandbox Code Playgroud)

到目前为止我用过

if_stmt ::=  "if" expression ":" suite
         ( "elif" expression ":" suite )*
         ["else" ":" suite]
Run Code Online (Sandbox Code Playgroud)

所以,这个'x if x <y else y'让我大吃一惊.你能指点我:在文档中我可以找到这种结构吗?

先感谢您

python-3.x

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

替换每个单词中除第一个字母之外的所有字母

text = "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,";

substitute_with = "_";

const regex = '\B[A-Za-z]';
// const regex = '\B\w';
// const regex = '(\w{1})\w*';

var result = text.replaceAll(regex, substitute_with);
Run Code Online (Sandbox Code Playgroud)

我想用下划线替换每个单词中除第一个字母之外的所有字母。

接下来我可以尝试什么?

javascript

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

C++:错误C2678:binary'=':找不到运算符,它接受类型为'const SPoint'的左手操作数

这是我的代码:

#include <StdAfx.h>;
#include <iostream>;
#include <vector>;
#include <algorithm>;
#include <iterator>;

using namespace std;
struct SPoint
{
    int id;
    int X;
    int Y;
};

bool operator<(const SPoint& p1, const SPoint&p2){
    return p1.id <p2.id;
}

vector<SPoint> points;
vector<SPoint> chosen;
vector<SPoint> cleared;

vector<SPoint>::iterator it;

void print_vect(const vector<SPoint> & vect)
{
    for (int i = 0; i < vect.size(); ++i)
    {
        cout << vect[i].id << " (" << vect[i].X << "," << vect[i].Y << ")"<<endl;               
    }           

    cout << endl;   
}
bool compare(double val1, …
Run Code Online (Sandbox Code Playgroud)

c++

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

c ++:在单独的情况下忽略cin.getline

由于某些原因,string cin.getline (temp.Autor, 20)它被忽略了.请看看输出 你能帮我理解为什么吗?

struct BOOK {
    char Autor[20]; 
    char Title[50]; 
    short Year; 
    int PageCount;
    double Cost;
};                  

void new_book()
{
    BOOK temp;
    system("cls");
    cout <<"ENTERING NEW BOOK: " << endl <<endl;
    cout <<"Input the author: ";
    cin.getline (temp.Autor, 20);
    cout  <<"Input the title: ";
    cin.getline (temp.Title, 50);
    cout  <<"Input the year of publishing: ";
    cin >>  temp.Year;
    cout  <<"Input the number of pages: ";
    cin >>  temp.PageCount;
    cout  <<"Input the cost: ";
    cin >>  temp.Cost; …
Run Code Online (Sandbox Code Playgroud)

c++ getline

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

C++:一个宏似乎有点奇怪

我刚开始学习c ++.原谅这样的问题.我的任务是编写一个宏来计算周长并测试它.

#define _USE_MATH_DEFINES
#include <cmath>

#define LENGTH(radius) (2 * M_PI * radius)

float l1 = LENGTH(1 + 2); // The result should be 18.8495... I have 8.28. Incorrect result.
float l2 = 1 / LENGTH(2); // The result should be  0.07957... Working correctly.
Run Code Online (Sandbox Code Playgroud)

我添加了额外的一对parenthethis:

float l1 = LENGTH((1 + 2)); // Correct result.
Run Code Online (Sandbox Code Playgroud)

如何编写这样的宏来获得正确的结果而不添加额外的括号?

c++

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

标签 统计

c++ ×3

python ×3

python-3.x ×3

dictionary ×1

getline ×1

java ×1

javascript ×1