我有一个字符串对象
final String demoString = "1,2,19,12";
Run Code Online (Sandbox Code Playgroud)
现在我想从中创建一个Collection.
我怎样才能做到这一点..?
我正在做论文,我必须将源代码解析并标记为单个函数.对于每个函数,我想提取类型的名称,称为函数名称和类型转换.铿锵声是这种工作的正确工具吗?如果是,我该怎么做?
下面是一个简单的C函数.粗体是我想要的提取项目:
static char func1(unsigned int a, struct foo *b) { int c = 0; struct bar *d; if (a == 0) { d = func2((int) a); } else { c = func3((struct bar *) b); } return c; }
是否有Linux命令或一系列命令,这将允许我以八进制(例如0644)格式获取文件的权限?
我想要一个哈希结构,每个以>开头的行是键,而直到下一个>的行是该键的值:
while (<DATA>) {
$line1 = $_;
chomp($line1);
if ($line1 =~ /^>/) {
while (<DATA>) {
last if $line1 =~ /^>/;
$value .= $_;
}
$hash{$line1} = $value;
}
}
foreach my $key(%hash) {
print "$key :$hash{$key}\n";
}
__DATA__
>label1
line1\n
line2\n
>label2
line1\n
line2\n
Run Code Online (Sandbox Code Playgroud) 我正在为我工作的公司编写一个C#程序,它将启动一个创建PDF的PHP脚本,然后打开PDF文件.现在,我有:
// launch the PHP page to generate my pdf report
Process.Start(phpFile);
// wait for the report to exist
Thread.Sleep(waitTime);
// open the report
Process.Start(filePath);
Run Code Online (Sandbox Code Playgroud)
现在,我不是一个整体的粉丝" Sleep()
在指定的时间内希望文件存在时完成".所以我的问题是,使用do
循环是否可行/更好并说:
do
{
// Do nothing until the file exists
} while (!File.Exists(filePath));
Run Code Online (Sandbox Code Playgroud) 我想检查当前年份是否大于日期字符串(DMY),这是我的代码
$OldDate = "09-30-2011";
$OldYear = strtok($OldDate, '-');
$NewYear = date("Y");
if ($OldYear < $NewYear) {
echo "Year is less than current year"
} else {
echo "Year is greater than current year";
}
Run Code Online (Sandbox Code Playgroud) 为什么这个递归函数最多只能计算(20!)?当我输入21时,它显示意外的结果.
#include <iostream>
using namespace std;
long long int factorial( long long int number )
{
if( number <= 1 )
return 1;
return number * factorial( number - 1 );
Run Code Online (Sandbox Code Playgroud)
}
int main()
{
long long int number;
while( cin >> number )
cout << factorial( number ) << endl; // factorial( 20 ) = 2432902008176640000
// factorial( 21 ) = -4249290049419214848 ????
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我试图从函数返回一个字符串数组,然后释放它使用的内存.代码如下:
int main(int argc, const char * argv[])
{
for (int m = 0; m < 10000; m++) {
char **data = dataTest();
int i = 0;
while(data[i]) {
printf("%p ",data[i]);
free(data[i]);
i++;
}
printf(" address= %p.\n",data);
free(data);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是功能:
char **dataTest()
{
char *row[] = {"this", "is", "a", "data", "string", NULL};
char **str = row;
char **dataReturn = (char **) malloc(sizeof(char *) * 6);
int i = 0;
while (*str) {
dataReturn[i] = malloc(sizeof(char) * strlen(*str)); …
Run Code Online (Sandbox Code Playgroud) 我正在尝试运行一个程序,该程序根据用户输入构造一个二维数组,然后打印该数组。必须以一种方法构造数组并以单独的方法打印行。我只想在新行上打印数组中的每一行。我不确定如何将数组从一种方法拉入另一种方法。
代码是这样设置的,所以当main
调用该方法时,它将调用“构造函数”方法来构建数组,然后在构建数组后,它将获取该数组并将数据发送到打印方法以打印每一行。我不确定从代码中的哪里开始,我仍然不明白如何从不同的方法中提取数据。
package workfiles;
import java.util.*;
import java.util.Scanner;
public class hw2
{
// Do not modify this method
public static void main(String[] args)
{
try {
int[][] iArray = enter2DPosArray();
System.out.println("The original array values:");
print2DIArray(iArray);
int[][] tArray = transposition(iArray);
System.out.println("The transposed array values:");
print2DIArray(tArray);
} catch (InputMismatchException exception) {
System.out.println("The array entry failed. The program will now halt.");
}
}
// A function that prints a 2D integer array to standard output
// THIS METHOD IS THE ONE …
Run Code Online (Sandbox Code Playgroud) 我目前面临的情况是我有String元组(大小为2),如果它们至少有一个共同的元素,则应该认为两个元组是相等的.我有以下课程实现这个想法:
public class MyTuple
{
private List<String> list = Arrays.asList(new String[2]);
public List<String> getList()
{
return list;
}
public void set(String firstElement, String secondElement)
{
list.set(0, firstElement);
list.set(1, secondElement);
}
@Override
public boolean equals(Object other)
{
if (other instanceof MyTuple) {
return !Collections.disjoint(this.list, ((MyTuple) other).getList());
}
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,根据hashCode()
合同:
如果两个对象根据equals(Object)方法相等,则对两个对象中的每一个调用hashCode()方法必须生成相同的整数结果.
如何覆盖我的hashCode()
方法不违反合同?