我试图从64 x 48位图中获取像素rgb值.我得到了一些价值,但远不及3072 (= 64 x 48)我期待的价值.我也得到:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!
at sun.awt.image.ByteInterleavedRaster.getDataElements(ByteInterleavedRaster.java:301)
at java.awt.image.BufferedImage.getRGB(BufferedImage.java:871)
at imagetesting.Main.getPixelData(Main.java:45)
at imagetesting.Main.main(Main.java:27)
Run Code Online (Sandbox Code Playgroud)
我找不到越界错误...
这是代码:
package imagetesting;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.io.File;
import java.awt.image.BufferedImage;
public class Main {
public static final String IMG = "matty.jpg";
public static void main(String[] args) {
BufferedImage img;
try {
img = ImageIO.read(new File(IMG));
int[][] pixelData = new int[img.getHeight() * img.getWidth()][3];
int[] rgb;
int counter = 0;
for(int i …Run Code Online (Sandbox Code Playgroud) 我正在尝试针对Hackerranks的"新年混乱"问题优化我的解决方案.问题的关键是这样的
有一个n个队列,标记为1到n,每个人都可以直接在他们面前贿赂这些人来交换位置并靠近队列的前面(在这种情况下,列表/数组的索引0).每个人最多只能贿赂两次(并且他们不能贿赂已经贿赂过他们的人)
在所有贿赂发生后,您将得到人民的命令,而您的工作是确定为达到这一点而发生了多少次贿赂.例如,如果你被给予[3,2,1],那么答案将是3次贿赂(第3个人被贿赂,第2个人被贿赂1人).
我的解决方案是,对于每个人,我计算一个标签大于我的左边的人数(他们将不得不贿赂我到他们左边的人).为了使事情变得复杂(稍微),只有有人贿赂2次以上(即[4,1,2,3] - 人4受贿的人3,然后2,然后1来到前方).如果是这种情况,只需输出"Too chaotic"
无论如何这里是代码:
# n is the number of people in the list
# q is the order of the people after the bribery has taken place ex. [1, 3, 2, 5, 4]
for I in range(1, n + 1): # for each person I in the list
index = q.index(I)
if I - index > 3: # more than two bribes
bribes = "Too chaotic"
break
for j in range(index): # for …Run Code Online (Sandbox Code Playgroud) 这是受保护方法的文档:
/** Converts jmusic score data into a MIDI Sequence */
protected javax.sound.midi.Sequence scoreToSeq(Score score)
Run Code Online (Sandbox Code Playgroud)
我创建了这个小类来扩展scoreToSeq方法来自的类:
public class MidiSequence extends MidiSynth{
public Sequence getSequence(Score score){
MidiSynth synth = new MidiSynth();
Sequence sequence = null;
try
{
// Here I get the error saying that the method has
// protected access in MidiSynth
sequence = synth.scoreToSeq(score);
}
catch (InvalidMidiDataException e)
{
/*
* In case of an exception, we dump the exception
* including the stack trace to the console.
* …Run Code Online (Sandbox Code Playgroud) 我有一些 Paramiko 代码,我使用 invoke_shell 方法在远程服务器上请求交互式 ssh shell 会话。方法概述如下:invoke_shell()
以下是相关代码的摘要:
sshClient = paramiko.SSHClient()
sshClient.connect('127.0.0.1', username='matt', password='password')
channel = sshClient.get_transport().open_session()
channel.get_pty()
channel.invoke_shell()
while True:
command = raw_input('$ ')
if command == 'exit':
break
channel.send(command + "\n")
while True:
if channel.recv_ready():
output = channel.recv(1024)
print output
else:
time.sleep(0.5)
if not(channel.recv_ready()):
break
sshClient.close()
Run Code Online (Sandbox Code Playgroud)
我的问题是:有没有更好的方式与 shell 交互?上面的工作,但它是丑陋的两个提示(matt@kali:~$ 和 $ 来自 raw_input),如使用交互式 shell 的测试运行的屏幕截图所示。我想我需要帮助写入 shell 的标准输入?抱歉,我代码不多。提前致谢!
我想在PowerShell中重复一个字符.例如:
$test = "this is a test that I want to underline with --------"
Write-Host $test
Write-Host "-" * $test.length
Run Code Online (Sandbox Code Playgroud)
但是,上面代码的输出是:
This is a test that I want to underline with --------
- * 53
Run Code Online (Sandbox Code Playgroud)
我错过了一些非常明显的东西吗
应该是一个非常简单的答案,但我现在无法弄清楚.我有这个按钮:
<button id="logout" type="button">Logout</button>
Run Code Online (Sandbox Code Playgroud)
它应该在正文底部的脚本标记内运行此jQuery代码:
$("#logout").addEventListener("click", function () {
alert('Button Clicked');
});
Run Code Online (Sandbox Code Playgroud)
但是,不会弹出警报.我不明白.提前致谢.
我让用户点击发送到他们的电子邮件的链接,将他们带到表格(例如,register.php)以完成他们的注册.
我在register.php上提交表单提交检查:
if(isset($_POST['submitted']) and $_SERVER['REQUEST_METHOD'] == 'POST') {
//register user in database
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:通过简单地创建一个带有$ _POST ['submitted']设置的自定义http POST请求,技术上有人可以绕过这个正式的注册过程吗?如果是这样,检查这个的好方法是什么?我检查有人试图以未经授权的方式进入注册页面,但我觉得有人在页面上发帖不够安全.如果我决定使用HTTPS,我是否应该担心这个?我希望这是有道理的.提前致谢.
我正在尝试在表单字段中使用jQuery进行电子邮件验证
$(document).ready(function() {
var email = new RegExp("[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$");
var value = $("#email_address").val();
$("#email_address").on("keypress", function() {
if(email.test(value)) {
$("#email_address").parent().addClass("has-success");
}
});
});
Run Code Online (Sandbox Code Playgroud)
但是,该has-success课程没有添加.我已经在控制台中单独尝试了每行代码,他们似乎都在做/指向正确的事情.当它全部放在一起时它似乎不起作用.
java ×2
javascript ×2
jquery ×2
python ×2
inheritance ×1
optimization ×1
paramiko ×1
php ×1
powershell ×1
protected ×1
rgb ×1
security ×1