我正在编写一个用户脚本,需要找到与另一个单词相关的单词.我找到了一个网站,我可以访问http://semantic-link.com/#/stack,并且会有一个与stack以下格式相关的单词列表:
<!-- various stuffs here, e.g. <head>, a <div>, another <div>, start of <body> -->
<div id="word0" class="word" onclick="updateTitle("stacks");" style="opacity: 1;">
stacks
</div>
<div id="word1" class="word" onclick="updateTitle("flue");" style="opacity: 1;">
flue
</div>
<div id="word2" class="word" onclick="updateTitle("popped");" style="opacity: 1;">
popped
</div>
<div id="word3" class="word" onclick="updateTitle("overflow");" style="opacity: 1;">
overflow
</div>
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我想stacks从该页面获取字符串.我发现的所有解决方案都不起作用,因为它们:
$.ajax(),, $.get()或$('something').load()仅限于执行它们的域.有没有什么办法可以#word0只使用JavaScript 将元素的内容作为字符串获取?或者,是否有另一种方法可以找到与另一个单词相关的单词?
我想知道为什么以及如何解决此数组方法输出的内存表示形式temp。
public class StringMethodsExersice{
public static int[] shiftMax(int[] num){
int temp[] = new int[num.length];
int firstEl = num[0];
int lastEl = num[num.length-1];
for(int i=1;i<num.length-1;i++){
if(num[i] > num[i+1]){
temp[i] = num[i];
}
temp[i] = num[i];
}
temp[0] = firstEl;
temp[num.length-1]= lastEl;
return temp;
}
public static void main (String []args){
int[] myArray = new int [5];
myArray [0] = 2;
myArray [1] = 5;
myArray [2] = 6;
myArray [3] = 14;
myArray [4] = 25;
System.out.println(shiftMax(myArray));
}
}
Run Code Online (Sandbox Code Playgroud) 所以我只是想看看我的数组中的元素是否可以被总和整除,我认为我的for循环总结了数组的元素有什么问题,关于我应该如何进行的任何提示?
public static void main(String[] args) {
int apa[] = {3,3,3};
System.out.print(allEqual(apa));
}
public static boolean allEqual(int[] a) {
int summa = 0;
boolean svar = true;
for (int i = 0; i <= a.length; i++) {
summa +=a[i];
}
if (summa % a.length == 0) {
return svar;
} else {
svar = false;
return svar;
}
}
Run Code Online (Sandbox Code Playgroud) 所以我刚读了一篇关于sizeof()C++书的章节.我读到的是,如果操作数是一个类型,你只需要sizeof之后的括号,你可以在有表达式时跳过括号,所以我做了自己的测试,看看这是怎么回事.我使用下面的代码来看看我会得到什么:
int main(){
cout << sizeof 5 + 5<< endl;
cout << sizeof 10 - 5<< endl;
cout << sizeof 5 * 5<< endl;
cout << sizeof 4.5 + 5.5<< endl;
cout << sizeof 10.5 - 5.5<< endl;
cout << sizeof 2.5 * 5<< endl;
cout << sizeof 10.0 / 5.0<< endl;
cout << endl;
cout << sizeof 5 << endl;
cout << sizeof 5.0 + 5.0 << endl;
cout << sizeof 5.5 << endl;
return 0;
} …Run Code Online (Sandbox Code Playgroud) 我试图找到的中位数a[p],a[r]和a[q]在那里q = r+p/2.我的程序崩溃,即使它在我创建median方法之前有效,所以我假设有什么问题.有谁知道什么是错的?
这是我运行程序时显示的内容:
Welcome to DrJava. Working directory is C:\coding
> run QuickSort
[5, 2, 7, 3, 9, 7, 10, 3, 6, 3, 7, 2, 6, 7, 2, 1]
java.lang.StackOverflowError
at QuickSort.partition(QuickSort.java:39)
at QuickSort.qSort(QuickSort.java:13)
at QuickSort.qSort(QuickSort.java:13)
at QuickSort.qSort(QuickSort.java:13)
.
.
.
at QuickSort.qSort(QuickSort.java:13)
at QuickSort.qSort(QuickSort.java:13)
>
Run Code Online (Sandbox Code Playgroud)
最后一行不断重复.
完整代码:
import java.util.*;
public class QuickSort {
public static void main(String[] args) {
Integer[] vals = new Integer[]{5,2,7,3,9,7,10,3,6,3,7,2,6,7,2,1};
System.out.println(Arrays.toString(vals));
qSort(vals,0,vals.length-1);
System.out.println(Arrays.toString(vals));
} …Run Code Online (Sandbox Code Playgroud) 在我的数据库中,我有username = user@javachap.com和密码= javachap
如果我运行下面的代码,它会通过测试,尽管我的数据库中不存在用户名和密码.
@Test
public void testLogin()
{
String username="abc";
String password="123";
boolean valueFound=false;
// Check the db
try
{
pstmt=conn.prepareCall("select * from user where USR_EMAIL=? and USD_PASSWORD=?");
pstmt.setString(1,username);
pstmt.setString(2,password);
rs=pstmt.executeQuery();
valueFound = rs.next();
}
catch(Exception e)
{
// report some error
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个程序,它列出了100到1000之间可被5或6整除的所有数字.这是我使用的代码:
public class divisibleBy5and6 {
public static void main (String[] args) {
j = 1;
int number = 100;
while (number < 1001) {
if (number % 6 == 0 || number % 5 == 0) {
System.out.print(number + ", ");
number++;
j++; }
if (j % 10 == 0 && j != 0) {
System.out.println();
j++; }
else {
number++;
}
}
Run Code Online (Sandbox Code Playgroud)
我曾经int j这样做,所以每行有9个.这是我的输出:
100, 102, 105, 108, 110, 114, 120, 125, 130,
132, 135, 138, 140, …Run Code Online (Sandbox Code Playgroud) 看看这个.java文件:
class A {
HashMap a;
}
Run Code Online (Sandbox Code Playgroud)
它不编译; 我需要import java.util.HashMap;.现在考虑一下:
class A {
String a;
}
Run Code Online (Sandbox Code Playgroud)
这是完全一样的,只是用String的,而不是HashMap-所以它不应该编译吧?错误.
好的,所以众所周知你不必导入String,但为什么呢?"显而易见"的答案是因为String使用频率远远超过HashMap,但是不ArrayList应该"隐式导入"?原始包装类怎么样,例如Integer和Boolean?ArrayList使用的频率远远超过Long和Float,但我必须导入ArrayList,不需要导入Float.
什么是落后不需要进口的原因String,Integer,Character,Exception和其他几个班?
在以下代码中
#include <stdio.h>
int main()
{
if (sizeof(int) > -1)
printf("True");
else
printf("False");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我得到输出为"False"而不是"True".我的理解是sizeof运算符只返回int的大小,在这种情况下为4.
为什么评估条件为假?
我有自己的基于 JDA 的 Discord BOT。我需要向特定频道发送短信。我知道如何将消息作为 onEvent 响应发送,但在我的情况下我没有这样的事件。
我有:作者(BOT)、令牌和频道号。
我的问题是:如何在没有事件的情况下将消息发送到此频道?
我只是重新阅读我的讲座脚本并在那里试用代码.问题是教授只给了我们代码片段,我真的坚持这个.我在Eclipse中不断收到此错误:
没有主要方法
即使我public static void main(String[] args)输入代码,我仍然会收到错误.我应该改变什么呢?
该程序的主要思想是计算平方根或平方根.
public class MeineKlasse {
private String job;
private String getJob() {
return job;
}
public void setJob(String job) {
this.job = job;
System.out.println(job);
}
public double myMethode(double x) throws Exception {
if (job.equals("quadrat"))
return x * x;
if (job.equals("wurzel"))
return Math.sqrt(x);
System.out.println(myMethode(x) + "=");
throw new Exception("Fehler:Aufgabe nicht korrekt definiert");
}
}
Run Code Online (Sandbox Code Playgroud) 它是一个Text speak转换器,它可以工作,直到我希望它在用户说"完成"时结束.我会用什么命令?
package textspeak;
import java.util.Scanner;
public class TextSpeak {
byte textspeak;
public static void main(String[] args) {
String brb = new String("brb");
String omw = new String("omw");
String btw = new String("btw");
String lol = new String("lol");
String omg = new String("omg");
String rofl = new String("rofl");
String fyi = new String("fyi");
String ftw = new String("ftw");
String idk = new String("idk");
String jk = new String("jk");
String ikr = new String("ikr");
String smh = new String("smh");
String ttyl …Run Code Online (Sandbox Code Playgroud) java ×9
arrays ×2
ajax ×1
c ×1
c++ ×1
discord ×1
discord-jda ×1
entry-point ×1
greasemonkey ×1
html ×1
import ×1
javascript ×1
jquery ×1
loops ×1
median ×1
methods ×1
output ×1
selenium ×1
sizeof ×1