我正在尝试创建一种填充方法,该方法采用用户指定的初始坐标,检查字符,然后根据需要进行更改。这样做之后,它将检查相邻的正方形并重复该过程。经过一些研究,我遇到了泛洪填充算法,并尝试了一下(它可以工作,但不能满足我的250 x 250字符数组的最大要求)。
我最初的洪水填充算法如下:
public static void fillArea (int x, int y, char original, char fill){
if (picture[y-1][x-1] != original){
return;
}
picture[y-1][x-1] = fill;
fillArea (x-1, y, original, fill);
fillArea (x+1, y, original, fill);
fillArea (x, y-1, original, fill);
fillArea (x, y+1, original, fill);
return;
}
Run Code Online (Sandbox Code Playgroud)
经过测试之后,我开始尝试使用Wikipedia上介绍的Queue方法,并且之前就类似问题询问过此问题。到目前为止,我已经提出了以下代码:
public static void fillArea (int x, int y, char original, char fill){
if (x != 0)
x--;
if (y!= 0)
y--;
Queue<Point> queue = new LinkedList<Point>(); …Run Code Online (Sandbox Code Playgroud) 假设我有项目和一个代表这些项目包含在结果中的N多热值向量:{0, 1}
N = 4
# items 1 and 3 will be included in the result
vector = [0, 1, 0, 1]
# item 2 will be included in the result
vector = [0, 0, 1, 0]
Run Code Online (Sandbox Code Playgroud)
我还提供了一个冲突矩阵,指示哪些项目不能同时包含在结果中:
conflicts = [
[0, 1, 1, 0], # any result that contains items 1 AND 2 is invalid
[0, 1, 1, 1], # any result that contains AT LEAST 2 items from {1, 2, 3} is invalid
]
Run Code Online (Sandbox Code Playgroud)
给定这个冲突矩阵,我们可以确定早期 …
有没有什么方法可以使用JavaScript(和jQuery)来创建一个只显示9GAG图像的网页,一次加载大约5个,并在一个向下滚动时加载更多?我正试图让自己更轻松地访问这些网站而不加载所有其他垃圾.
谢谢.
我试图以类似于表格的格式输出关于我的程序存储的学生的信息,因为\ t并不总是提供正确的间距.为了做到这一点,我遇到了这个问题并试图启用类似的解决方案.但是,当我尝试执行它时,我在代码中获取格式行的错误.
public void displayStudents (){
System.out.println ("\n-----------------------------");
System.out.println ("Email System - Display Students");
System.out.println ("-----------------------------");
System.out.format("%10s%15d%15s%15s%20s", "Grade", "Last Name", "First Name", "Student Number", "Parent Email");
StudentNode current = top;
while (current != null){
Student read = current.getStudentNode();
System.out.format ("%10s%15d%15s%15s%20s", ""+read.getClass(), read.getLastName(), read.getFirstName(), ""+read.getStudentNum(), read.getParentEmail());
//This will output with a set number of character spaces per field, giving the list a table-like quality
}
}//End of displayStudents
Run Code Online (Sandbox Code Playgroud)
代码的目标是以类似于下图的方式输出.

请帮助我找到我的错误.是否有一种替代方法可以执行此操作?
谢谢.
编辑:我得到的错误是
GradeException in thread "main" java.util.IllegalFormatConversionException: d != …Run Code Online (Sandbox Code Playgroud) 我试图从格式如下的文件中提取信息:
1
test@mail.ca|password|false
Run Code Online (Sandbox Code Playgroud)
但是,我似乎ArrayIndexOutOfBounds在运行以下代码时遇到错误,我无法确定原因,因为我认为我的分裂应该正常运行.在以"users"开头的行上获得错误.
sc = new Scanner (System.in);
BufferedReader in = new BufferedReader (new FileReader (USAVE));
int repeats = Integer.parseInt(in.readLine());
for (int c = 0; c < repeats; c++){
String info = in.readLine();
System.out.println (info);
String[] extracted = info.split("\\|");
users.addUser(extracted[0], decryptPassword(extracted[1]));
}
in.close();
Run Code Online (Sandbox Code Playgroud)
可能是什么问题呢?
编辑:我改变了"|" 到"\ |" 但问题仍然存在.
EDIT2:StackTrace
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at OnlineCommunications.userFromFile(OnlineCommunications.java:165)
at OnlineCommunications.logIn(OnlineCommunications.java:36)
at OnlineCommunications.emailOption(OnlineCommunications.java:593)
at OnlineCommunications.main(OnlineCommunications.java:683)
Run Code Online (Sandbox Code Playgroud)
我上面发布的方法是名为userFromFile.
我需要一个动态的"数据库"对象,经过一番研究,决定使用ArrayList.但是,我无法使用以下代码修改arraylist:
public static ArrayList cprofiles;
...
cprofiles = new ArrayList();
...
...
Customer newc = new Customer (lna, fna, sinum, year, month, day);
cprofiles.add (newc);
Run Code Online (Sandbox Code Playgroud)
在此声明之后,我尝试使用以下格式调用对象内的方法,cprofiles.get(0).getName()但我收到错误说明
找不到符号(指向.getName())
当我尝试编译程序时.我花了大约一个小时来研究在ArrayList中修改它的正确方法,但是我发现的来源似乎暗示我正在做的事情确实是正确的.请帮助我发现我的错误以及如何解决它.
谢谢!
java ×4
arrays ×2
arraylist ×1
css ×1
database ×1
flood-fill ×1
formatting ×1
html ×1
javascript ×1
jquery ×1
numpy ×1
numpy-einsum ×1
oop ×1
python ×1
queue ×1
recursion ×1