我在Java编程方面还是个新手。我刚刚了解了数组,做了几次测试,结果遇到了麻烦。
import java.util.Scanner;
class oranges {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
int user_input;
whatever whateverObject = new whatever();
System.out.println("Enter 1 to dem
我一直遇到的问题是,上面写着java.lang.ArrayIndexOutOfBoundsException: 165
165是它实际应该包含的值的数目。
我试着将整数数组的长度更改为更大的数字,但它一直给我错误,尽管它的数字更大。
我把所有的东西都打印出来,看看问题是否是我的for循环,但是那里的一切看起来都很好(165个数组中有正确的数字)。
我看不出问题出在哪里。
public int[][] getTilePositionsIn(int pixelLeft, int pixelBottom, int pixelRight, int pixelTop){
int starterT
我试图检查数组中是否存在整数值,但即使该整数存在于数组中,该函数仍返回false。
这是我正在使用的代码。错误为404,但返回false:
const
cErrors: array [0 .. 3] of integer = (401, 404, 409, 411);
function isInError(const error: integer; const sArray: array of integer): Boolean;
var
i: integer;
begin
Result := False;
for i in sArray do
if sArray[i
我的问题是,如何能够在Java中创建一个随机生成的迷宫?我知道DFS创建迷宫的主要方法,但我很难实现它。在我的程序中,迷宫被保存在一个2D数组中,将1添加到数组中会产生一个超出边界的异常。我怎么才能避免呢?我不想制造一个非常复杂的迷宫,只是一个简单的迷宫。虽然我已经开始创建代码,但我不知道如何使它工作。
DFS方法的伪码是:
create a CellStack (LIFO) to hold a list of cell locations
set TotalCells = number of cells in grid
choose a cell at random and call
给定一个2d数组矩阵,目标是定位所有相邻的坐标,实例化它们为对象,并将它们添加到ArrayList中供以后使用。我遇到的问题是,考虑到边缘情况下,邻居可能超出矩阵的界限。这样,在Java中说明2d数组的界限以便可能被条件语句捕获的最佳方法是什么?
试过以下几点。不确定如何解释邻居之一超出矩阵界的情况(例如。一个只有两个邻居的角节点)。
import java.util.ArrayList;
class Node{
private int nodeX;
private int nodeY;
public Node(int enterX, int enterY){
下面是我非常非常精简的版本,只包括布尔值及其周围的结构:
public int payoffDebt(Double totalDebt) {
boolean booIsPaid[] = new boolean[c.getCount()];
int bb = 0;
int bbb = 0;
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
booIsPaid[bb++] = false;
}
while (totalDebt > 0) {
为什么阿瑞是零?使用printf函数进行测试后,它显示该位置为arr[0][-1],其值为0,如下面的结果所示。
int main() {
int arr [2][4];
int i,j;
for (i=0; i<2; i++) {
for (j = 0; j < 4; j++) {
printf("Provide a number: ");
scanf("%d", &arr[i][j]); // get the values
printf("The arr[i][j] i
在我的代码中,我在while循环之前定义了一个步骤大小"h“。当我试图在循环中使用它时,它似乎会自行改变。如果我在循环中定义它,它似乎是正常的,但我得到的数据似乎不正确,所以我猜问题可能是相关的。
即使我在这个位置打印它(请参阅代码中的printf ),输出也是3个值,我不知道为什么。如果您看到任何与此无关但似乎是错误的东西,请告诉我,正如我所说的,我得到了意想不到的值(这可能只是我的公式)。
int main()
{
FILE *f1;
f1 = fopen("Question2 part 3 solution.txt", "w");
我一直在使用一个服务,它返回一个JSON文件,其中包含一个数组和一个数组中的对象。第二层数组的问题是我似乎不能使用它。JSON看起来像这样:
{
"section": "U.S.",
"subsection": "Politics",
"title": "To Understand Clinton’s Moment, Consider That It Came 32 Years After Ferraro’s",
"abstract": "A look bac
下面是我的实现的源代码
#include <iostream>
using namespace std;
int partition (int arr[], int l, int h)
{
int pivot = arr[l];
int i=l;
int j=h;
while (i<j)
{
while(arr[i] <= pivot) ++i;
while(arr[j] > pivot) --j;
if (i>=j) break;
swap(ar
这是问题语句:,我的代码是:
#include<stdio.h>
#include<string.h>
char p[100];
char n[100][100];
int main()
{
int a,c=0;
int x,y,z=0;
scanf("%d",&a);
while(a--)
{
int mid,l,i,j,f;
scanf("%s",p);
这就是我如何在c中实现分区函数的方法。
int partition(int arr[], int start, int end)
{
int i = start;
int j = end;
int pivot = arr[i];
while (i < j)
{
do
{
i++;
} while (arr[i] < pivot);
do
{
j--;
} while (arr[j] > p
我似乎不知道我的方法"public static int sellSeatByPrice“的参数应该是什么。我需要提示用户一个价格(座位),然后确定这个价格是否被接受(如果它= 0),如果没有,则将其赋值为0。
下面是我的代码,请帮帮忙!
import java.util.Scanner;
/**
* Write a description of class A10_TheaterSeating here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class A10_T
当我试图运行这段代码时,它显示java.lang.ArrayIndexOutOfBoundsException错误。请帮我修复这个代码。
import java.util.*;
class Example {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
Random r = new Random();
final int N, S;
System.out.print("Input No of Students : ");
我的程序停止读取更多的行,在这个过程之后结束程序,就像它的“结束”一样。之后(但不是):
Procedure BubbleSort;
var i, j : integer;
begin
for i := 0 to count - 1 do begin
for j := count - 1 downto i do
if (together[j] > together[j - 1]) then
Swap(together[j - 1], together[j]);
end;
end;
import java.util.Scanner;
public class StringRotator {
public static void main(String[] args) {
Scanner Scanner = new Scanner(System.in);
System.out.println("Enter String");
String str = Scanner.next();
System.out.println("How many letters should be rotated?");
我是java的新手,今天我开始研究数组,我迷失了方向。我试图将一些值放入一个数组中,但是我得到了错误java.lang.ArrayIndexOutOfBoundsException。
以下是我到目前为止所做的工作。
int n=6;
int[]A= new int [1];
for(i=0;i<n;i++){
A[i]=keyboard.nextInt();
}
我试图制作一个空间入侵者游戏,使用数组来存储入侵者,但是每次我运行代码时,它都会冻结,并且错误的是我的数组大小不对。
错误:
System.OutOfMemoryException类型的未处理异常发生在mscorlib.dll中
有人能帮忙吗?这是我的代码:
class invaders
{
ingame game = new ingame();
PictureBox[] spaceinvaders = new PictureBox[100];
public void spawn(int level)
{