如何在单元测试中测试 hashCode()函数?
public int hashCode(){
int result = 17 + hashDouble(re);
result = 31 * result + hashDouble(im);
return result;
}
Run Code Online (Sandbox Code Playgroud) 可以在localhost上测试" Like "按钮吗?
我在使用jstl时遇到了一些问题.我有这个:
<jsp:useBean id="view" class="user.View"></jsp:useBean>
<jsp:useBean id="user" class="user.Validation" scope="session"></jsp:useBean>
<c:if test="${user.getValid() == 0}">
<c:out value="${view.printUserData(user)}"></c:out>
</c:if>
Run Code Online (Sandbox Code Playgroud)
和View类看起来:
package user;
import java.lang.StringBuilder;
public class View {
public String printUserData(Validation val) {
String name = val.getImie();
mainText.append(name);
return mainText.toString();
}
}
Run Code Online (Sandbox Code Playgroud)
但我有错误:
org.apache.jasper.JasperException:/save.jsp(30,0)当默认命名空间不是特定的时,函数getValid必须与前缀一起使用
我该如何解决?
我收到错误:
ERROR [NewsDAO] findAll(): org.postgresql.util.PSQLException: Multiple ResultSets were returned by the query.
Run Code Online (Sandbox Code Playgroud)
我使用postgresql-8.4-703.jdbc4.jar.
我的代码看起来像:
private static StringBuilder findAllQuery = new StringBuilder();
{
findAllQuery.append("SELECT * FROM news;");
}
public List<News> findAll() {
Statement stm = null;
ResultSet rs = null;
List<News> results = new ArrayList<News>();
if (obtainConnection()) {
try {
stm = con.createStatement();
rs = stm.executeQuery(findAllQuery.toString());
while(rs.next())
results.add(setInObject(rs));
} catch (Exception e) {
logger.error("findAll(): " + e);
} finally {
logger.info("Zamknalem");
closeConnection();
}
}
return results;
}
public News setInObject(ResultSet rs) …Run Code Online (Sandbox Code Playgroud) 如果用空格分隔,我怎么能得到像"Ac milan"和"Real Madryt"这样的字符串?
这是我的尝试:
string linia = "Ac milan ; Real Madryt ; 0 ; 2";
str = new char [linia.size()+1];
strcpy(str, linia.c_str());
sscanf(str, "%s ; %s ; %d ; %d", a, b, &c, &d);
Run Code Online (Sandbox Code Playgroud)
但它不起作用; 我有:a= Ac; b = (null); c=0; d=2;
我有功能:
int read_file() {
ifstream file("plik");
if(!file.is_open()) {
throw -1;
}
int i = 0;
string line[MAXSIZE];
while(getline(plik, line[i])) {
cout<<line[i]<<endl;
i++;
}
return i;
}
Run Code Online (Sandbox Code Playgroud)
但我想返回字符串数组:
line[]
我怎样才能做到这一点?
我想用mpi运行一些函数,main但我不知道它应该如何.看起来像:
#define MAXSIZE 100
int main (int argc, char **argv) {
int i;
float matrixA[MAXSIZE][MAXSIZE], matrixB[MAXSIZE][MAXSIZE], matrixC[MAXSIZE][MAXSIZE];
for(i=0;i<10;i++){
multiply(matrixA, matrixB, matrixC);
}
}
void multiply(float matrixA[MAXSIZE][MAXSIZE], float matrixB[MAXSIZE][MAXSIZE], float matrixC[MAXSIZE][MAXSIZE]) {
int rank; //process rank
int size; //number of processes
MPI_Init(&argc, &argv); //initialize MPI operations
MPI_Comm_rank(MPI_COMM_WORLD, &rank); //get the rank
MPI_Comm_size(MPI_COMM_WORLD, &size); //get number of processes
...someoperation...
MPI_Finalize();
}
Run Code Online (Sandbox Code Playgroud)
我知道如何在不使用其他功能的情况下运行基本MPI,但我需要这种结构.
我想使用 Jama 库将 2 个矩阵相乘,但它返回:
A col: 4 row: 4
B col: 1 row: 4
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Matrix dimensions must agree.
Run Code Online (Sandbox Code Playgroud)
我的代码:
double[][] arrA = { {1,0,0,0}, {0, Math.cos(0.34), -Math.sin(0.34), 0}, {0, Math.sin(0.34), Math.cos(0.34), 0}, {0,0,0,1} };
double[][] arrB = { {x}, {y}, {z}, {1} };
Matrix A = new Matrix(arrA, 4, 4);
Matrix B = new Matrix(arrB, 4, 1);
A.print(1, 1);
B.print(1, 1);
System.out.println("A col: " + A.getColumnDimension() + " row: " + A.getRowDimension());
System.out.println("B col: …Run Code Online (Sandbox Code Playgroud) 我有这个:
String data[][] = null;
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
data[i][j]= "test";
}
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用.变量数据为空.