在JavaDoc中插入类的创建日期的最佳方法是什么?一些例子:
在author标签下面,带有字符串"created on"
/**
* Class description
*
* @author Author Name
* created on 2015/04/01
*/
public class ClassName() {
...
}
Run Code Online (Sandbox Code Playgroud)
在author标签下面,带有字符串"Date:"
/**
* Class description
*
* @author Author Name
* Date: 2015/04/01
*/
public class ClassName() {
...
}
Run Code Online (Sandbox Code Playgroud)
使用不存在的@date标记
/**
* Class description
*
* @author Author Name
* @date 2015/04/01
*/
public class ClassName() {
...
}
Run Code Online (Sandbox Code Playgroud)
其他...
最终,最好的日期格式是什么?
April 1, 2015
2015/04/01
...
Run Code Online (Sandbox Code Playgroud) [问题1]
当我将文件打开到函数中时,通常我会这样做:
int read_file (char *filename)
{
FILE *fin;
if ( !(fin = fopen(filename, "r")) )
return 1;
/* ... */
return fclose(fin);
}
int main ()
{
char filename[100];
if ( read_file(filename) )
{
perror(filename);
exit(1);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
通常0返回值是错误(对吗?)然后我可以将以前的代码更改为:
int read_file (char *filename)
{
FILE *fin;
if ( !(fin = fopen(filename, "r")) )
return 0;
/* ... */
return !fclose(fin);
}
int main ()
{
char filename[100];
if ( !read_file(filename) )
{
perror(filename);
exit(1);
} …Run Code Online (Sandbox Code Playgroud) 将Singleton的实例声明为static或更好static final?
请参阅以下示例:
static 版
public class Singleton {
private static Singleton instance = new Singleton();
private Singleton() {
}
public static Singleton getInstance() {
return instance;
}
}
Run Code Online (Sandbox Code Playgroud)
static final 版
public class Singleton {
private static final Singleton INSTANCE = new Singleton();
private Singleton() {
}
public static Singleton getInstance() {
return INSTANCE;
}
}
Run Code Online (Sandbox Code Playgroud) 在下面的代码中,我向函数传递指针*example[10];或整个数组?
#include <stdio.h>
void function (int **)
int main ()
{
int *example[10];
function(example);
return 0;
}
void function (int *example[10])
{
/* ... */
return;
}
Run Code Online (Sandbox Code Playgroud)
以下代码的相同问题:
#include <stdio.h>
struct example
{
int ex;
};
void function (struct example *)
int main ()
{
struct example *e;
function(e);
return 0;
}
void function (struct example *e)
{
/* ... */
return;
}
Run Code Online (Sandbox Code Playgroud) 考虑以下简单的代码行:
public class Main {
public static void main(String[] args) {
String string = "Lorem,ipsum,dolor,sit,amet";
String[] strings = string.split(",");
for (String s : strings) {
System.out.println(s);
}
}
}
Run Code Online (Sandbox Code Playgroud)
正如预期的那样,输出如下:
Lorem
ipsum
dolor
sit
amet
Run Code Online (Sandbox Code Playgroud)
现在考虑前面的代码中,我只是把的变化,为|:
public class Main {
public static void main(String[] args) {
String string = "Lorem|ipsum|dolor|sit|amet";
String[] strings = string.split("|");
for (String s : strings) {
System.out.println(s);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我期待相同的输出,但奇怪的是以下内容:
L
o
r
e
m
|
i
p
s
u
m …Run Code Online (Sandbox Code Playgroud) 我的问题是'realloc'.以下代码正常工作(没有警告):
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int num=10;
int *vet;
int i;
for (i=0; i<num; i++)
{
/* allocate memory of vet to contains (i+1) int */
vet = (int*) realloc ( vet, (i+1) * sizeof(int) );
/* write numbers in the allocated memory */
vet[i] = 321 + i;
}
/* print test, if all works I must see:
| 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | …Run Code Online (Sandbox Code Playgroud) 如果我有struct example *e,那么function(&e)和之间有什么区别function(e)?
一个例子.
这是第一个代码:
#include <stdio.h>
struct example
{
int x;
int y;
};
void function (struct example **);
int main ()
{
struct example *e;
function (&e);
return 0;
}
void function (struct example **e)
{
/ * ... */
}
Run Code Online (Sandbox Code Playgroud)
这是第二个代码:
#include <stdio.h>
struct example
{
int x;
int y;
};
void function (struct example *);
int main ()
{
struct example *e;
function (e);
return 0;
}
void function (struct …Run Code Online (Sandbox Code Playgroud) 我有一个有num行的文件:每行包含一个数字.我想将每个数字保存到矢量中*vet.为什么这段代码不起作用?
Segmentation fault (core dumped)
我认为错误是sscanf在save_numbers功能,但我不知道为什么.
#include <stdio.h>
#include <stdlib.h>
/* This function allocate memory
and save numbers into a vector */
int save_numbers (int **vet, int *num)
{
FILE *fin;
int i = 0;
char buff[10];
if ( !(fin = fopen("numbers.dat", "r")) )
return 1;
while ( fgets(buff, sizeof(buff), fin) )
{
*vet = (int *) realloc (*vet, (i+1) * sizeof(int) );
sscanf (buff, "%d", vet[i]);
i++;
}
*num = i; …Run Code Online (Sandbox Code Playgroud) 如果我可以使用for和while两个循环,我应该选择哪个?
[对于]
int num = 10;
int i;
for (i=0; i<num; i++)
{
/* ... */
}
Run Code Online (Sandbox Code Playgroud)
[而]
int num = 10;
int i = num;
while ( i-- )
{
/* ... */
}
Run Code Online (Sandbox Code Playgroud) 我编写了i程序,它将翻转一个句子并将其打印出来.
在这段代码中,我得到的所有单词都是正确的,除了最后一个.即在反转代码中的句子之后,"hiii"仍然是"iiih",其余的输出是正确的.
void reverse(char * s, int len){
int counter = 0;
int end = len - 1;
char temp;
for (counter = 0; counter < len / 2; counter++, end--) {
temp = s[counter];
s[counter] = s[end];
s[end] = temp;
}
}
int main(void){
char s[] = "hiii all i want to reverse this sentence so please help me fast";
int c = 0;
int len = strlen(s);
int wl = 0;
int start = 0;
printf("\n s = …Run Code Online (Sandbox Code Playgroud)