在我的当前项目中,我必须在java项目中实现本机c++库的功能。我在用JNA。到目前为止已经取得了一些不错的效果。现在我被困在下面的问题上了。
我必须调用本机c函数:
int retrieveResult(ResultStruct * pResult)
结构的定义如下:
typedef struct tag_ResultStruct
{
const void *pBuffer;
int sizeX;
int sizeY;
} ResultStruct;
在Java中,我创建了一个表示结构的类:
public class ResultStruct extends Structure{
pu
我正在尝试为类创建一个程序,当用户输入系数时,该程序计算给定方程的判别式。不过,我在将输入从字符串转换为int时遇到了问题。我的老师一心想要确保我让用户在一行中输入所有的系数,这就是问题所在。 到目前为止,我的代码如下: /*
* Write a program that will determine the number and type of roots
* for a quadratic equation, given the coefficients a, b, and c.
*/
import java.util.Scanner;
public class Main
{
它的构建没有问题,但当我插入短语时,它会在常规输出框中显示以下错误:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 2
at java.lang.String.charAt(String.java:686)
at encoder.main(encoder.java:77)
Process completed.
谁能告诉我这个问题是什么以及如何解决它?
代码如下:
/**
* @(#)encoder.java
*
我对创建一个具有运行时间和空间约束的简单数组问题感兴趣。看来我已经找到了解决问题的办法。请阅读以下java代码中对此问题的初始描述注释:
/*
* Problem: Given two integer arrays, a and b, return whether array a is a permutation of array b.
* Running time complexity: O(n)
* Space complexity: O(1)
* Example 1:
* a = [1, 2, -3]
* b = [2, 3, 1]
* false
* Example
import java.util.*;
import java.lang.*;
import java.io.*;
public class ArrayUtilities {
public static void main(String[] args) {
}
public static boolean linearSearch(int[] array, int target) {
int i;
for (i = 0; i < array.length; i++) {
if (array.charAt(i) == target) {
我试图理解java String是如何实现的implemented.The jdk7 source代码,下面显示了检查originalValue.length > size .I无法确定如何/何时实现。我试图在一些java字符串创建语句上使用eclipse调试器,但是这个检查永远不可能设计一个字符串参数,从而使这个检查成为现实?
public final class String{
/** The value is used for character storage. */
private final char value[];
/** The offset
我正在尝试写一个java程序,其中一个数组代表名称(字符串),另一个代表年龄(整数),程序应该迭代并要求每个名称和年龄的最大值为10,然后显示所有数组项以及每个数组项的最大和最小年龄,或者除非用户中途输入“DONE”或“DONE”。
我有以下代码,虽然很难循环,并要求用户的姓名和年龄x10。
有什么建议吗?
谢谢。
import java.util.Scanner;
public class AgeName {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
我试图编写一个简单的Java程序,它可以从用户指定的矩阵中的任何位置开始遍历矩阵(2D-Array)。
我首先声明我的矩阵并用随机数填充它,但我不知道从这里往哪里走?我如何能够从随机位置开始遍历矩阵中的每个单元?
我只是想有一些基本的和不太先进的东西,因为我仍然是一个初学者在Java,任何帮助都会非常感谢!
public static void main(String[] args) {
// Initialize Matrix randomly
int R = 3;
int C = 3;
int[][] mat
这就是代码,它的目的是从列表中给出一个随机的单词,让用户输入外部文本文件中的含义,如果正确,它会从列表中删除这个单词,否则它会保留这个单词,并将其添加到missedWord列表中。问题是这些单词没有从列表中删除,而且我似乎无法打印ArrayList。有人能帮我解决这个问题吗?另外,我可以对代码做些什么改进吗?谢谢你的帮助。
import java.io.*;
import java.util.*;
public class WordList1 {
public static void main(String[] args) throws IOException{
boolean fa
我正在尝试将数字反转为int数字,但下面提供的代码返回错误:
Exception in thread "main" java.lang.NumberFormatException: For input string: "[null, null, null]"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:492)
at java.lang.
我正在尝试理解Array对象,我想要做的是在我拥有的每个类中调用我的数组。
这是我的密码:
projectProva.java
public class ProjecteProva {
Scanner sc = new Scanner(System.in);
private final int maxContador = 4;
private final DadeArr LlistaUsuari[] = new DadeArr[maxContador];
int ContadorActual;
我不一定知道如何使用循环来创建数组元素和打印。我的作业要求我创建一个新的整数数组,名为nameLengths。编写一个循环来迭代先前创建的名称数组,并将每个名称的长度添加到nameLengths数组中。
我在谷歌上到处搜索,看了很多其他人类似的问题,但不太清楚如何在我的特定代码中实现它。
import java.lang.reflect.Array;
public class arrays {
public static void main(String[] args) {
// TODO Auto-generated method stub
int
我是一个开发java应用程序的初学者。我在android上做一个聊天应用。我使用线程为进入的客户端提供服务,但是当客户端连接到服务器时,我无法检索套接字中包含的数据,但是当客户端连接断开时,可以显示数据。我使用ReadLine方法从套接字读取数据。这是服务器端的程序代码:
package server;
import java.net.*;
import java.io.*;
import java.util.Vector;
import com.sun.org.apache.bcel.internal.generic.NEW;
public class Server {
我正在学习KMP字符串匹配算法,以便在给定的字符串中找到模式的总出现次数。我的部分代码如下,用java实现:
void kmpMatcher( string text, string pattern) {
int counter = 0;
int n=text.length();
int m=pattern.length();
int [] pi = computePrefix(); // computes the prefix array
int q = 0;
for (int i=0;i<n;i++) {
while(q
这些append()方法如何模棱两可?
public class Try_MultipleArguments {
public static void main(String[] args) {
int array1[] = new int[] {1, 2, 3};
int array2[] = new int[] {4, 5, 6};
append(array1, array2);
append(array1, 4, 5, 6);
}
public static int[] append(i
我有java包,有hosts和Client类,它们可以产生许多主机
public final class Host {
public final String name;
public final int port;
}
public class SomeClient{...
public Client(Host... hosts) throws Exception {
....
}
我正在编写scala代码来创建这个客户机
// the hosts example is hosts1,host2,host3
def getClient(hosts:String)