如何在JavaScript中创建无限循环?我正在尝试制作幻灯片,我已经开始工作了,但我无法让它循环播放.我甚至无法让它循环两次.
我现在使用的代码是
window.onload = function start() {
slide();
}
function slide() {
var num = 0;
for (num=0;num<=10;num++) {
setTimeout("document.getElementById('container').style.marginLeft='-600px'",3000);
setTimeout("document.getElementById('container').style.marginLeft='-1200px'",6000);
setTimeout("document.getElementById('container').style.marginLeft='-1800px'",9000);
setTimeout("document.getElementById('container').style.marginLeft='0px'",12000);
}
}
Run Code Online (Sandbox Code Playgroud)
没有那里的东西,它确实经历了一次.当我输入一个for时,它要么让Firefox锁定,要么只循环一次.我确信这是一件非常简单的事情,即使它必须循环1,000,000次而不是无限次,这对我来说还算合适.
另外,我不想使用jQuery或其他人创建的东西.我正在学习JavaScript,这部分是为了帮助我学习,部分是因为我正在努力制作尽可能多的基于HTML5的系统.
编辑:我认为它冻结的原因是因为它一次执行代码,然后只是将它存储在缓存或其他东西.我想要它做的就是经历一次,然后再次从顶部开始,这是我一直认为循环的地方.在"批处理"(命令提示符)脚本中,可以使用" GOTO
"命令完成.我不知道JS中是否有相同的东西,但这确实是我的目标.
如果输入是'ABBA',那么可能回文是a,b,B,A,BB,ABBA.
我知道确定弦是否是回文很容易.这将是:
public static boolean isPalindrome(String str) {
int len = str.length();
for(int i=0; i<len/2; i++) {
if(str.charAt(i)!=str.charAt(len-i-1) {
return false;
}
return true;
}
Run Code Online (Sandbox Code Playgroud)
但找到回文子串的有效方法是什么?
当我使用JDK5时如下
ArrayList<Integer> list = new ArrayList<Integer>();
for (Integer i : list) {
//cannot check if already reached last item
}
Run Code Online (Sandbox Code Playgroud)
另一方面,如果我只是使用一个 Iterator
ArrayList<Integer> list = new ArrayList<Integer>();
for (Iterator i = list.iterator(); i.hasNext();) {
//i can check whether this is last item
if(i.hasNextItem()){
}
}
Run Code Online (Sandbox Code Playgroud)
如何检查我是否已经使用了最后一项 for (Integer i : list) {
我维护JDOM项目,我试图在Android上'认证'它.大多数工作都很好,但XML Schema验证证明是有问题的......
我的问题是:有没有办法在Android上进行XMLSchema验证?如果有,怎么样?
之前曾有人问过这样的问题,但没有给出确凿的答案:
这就是我目前所知道的(如果我错了,请纠正我)......:
我一直在研究这个问题已经有一段时间了,我已经整理了以下"研究":
如果有人在Android上有关于XMLSchema验证的任何更多信息,我将非常感谢任何输入.
如果有人成功地对XML进行了XMLSchema验证并且可以帮助我获得适用于JDOM的功能,那么他们将获得数千个互联网点... ;-)并将在JDOM代码中永生化并提交消息.
一位朋友给了我一个谜语:
#include<stdio.h>
#define TOTAL_ELEMENTS ((sizeof(array) / sizeof(array[0])))
int array[] = {23,34,12,17,204,99,16};
int main()
{
int d;
for(d=-1;d <= (TOTAL_ELEMENTS-2);d++)
printf("%d\n",array[d+1]);
getchar();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
上面的代码应该打印所有的数组元素,代码中的问题是什么(输出什么都没有)?我认为循环不会迭代一次?
我发现以下代码确实有效:
#include<stdio.h>
#define TOTAL_ELEMENTS ((sizeof(array) / sizeof(array[0])))
int array[] = {23,34,12,17,204,99,16};
int main()
{
int d;
int x = (TOTAL_ELEMENTS-2);
for(d=-1;d <= x;d++)
printf("%d\n",array[d+1]);
getchar();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我有一个理论认为它与宏有关,但我不能指责问题.
Code Review聊天中的讨论确定了ScheduledExecutorService的以下行为:
计划运行的任务失败并出现"严重"问题,但没有问题的报告,异常或日志.在其他情况下,应用程序通常会以错误终止.但是,在ScheduledExecutorService的上下文中,根本没有异常/错误"处理".
首先,要制造一个问题.以下类具有保证失败的静态初始化程序:
public class InitializerFault {
private static final int value = Integer.parseInt("fubar");
@Override
public String toString() {
return "" + value;
}
}
Run Code Online (Sandbox Code Playgroud)
运行时:
public static void main(String[] args) {
System.out.println(new InitializerFault());
}
Run Code Online (Sandbox Code Playgroud)
它产生(这正是我所期望的):
Exception in thread "main" java.lang.ExceptionInInitializerError
at SimpleHandler.main(SimpleHandler.java:5)
Caused by: java.lang.NumberFormatException: For input string: "fubar"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.parseInt(Integer.java:615)
at InitializerFault.<clinit>(InitializerFault.java:4)
... 1 more
Run Code Online (Sandbox Code Playgroud)
但是,当运行时:
private static final Thread buildThread(Runnable r) {
Thread t = new Thread(r, "TestThread");
t.setDaemon(true);
System.out.println("Built thread …
Run Code Online (Sandbox Code Playgroud) 我想在使用os包中创建一个相对符号链接.
os已包含函数:os.SymLink(oldname, newname string)
,但它无法创建相对符号链接.
例如,如果我运行以下内容:
package main
import (
"io/ioutil"
"os"
"path/filepath"
)
func main() {
path := "/tmp/rolfl/symexample"
target := filepath.Join(path, "symtarget.txt")
os.MkdirAll(path, 0755)
ioutil.WriteFile(target, []byte("Hello\n"), 0644)
symlink := filepath.Join(path, "symlink")
os.Symlink(target, symlink)
}
Run Code Online (Sandbox Code Playgroud)
它在我的文件系统中创建以下内容:
$ ls -la /tmp/rolfl/symexample
total 12
drwxr-xr-x 2 rolf rolf 4096 Feb 21 15:21 .
drwxr-xr-x 3 rolf rolf 4096 Feb 21 15:21 ..
lrwxrwxrwx 1 rolf rolf 35 Feb 21 15:21 symlink -> /tmp/rolfl/symexample/symtarget.txt
-rw-r--r-- 1 rolf rolf 6 Feb …
Run Code Online (Sandbox Code Playgroud) 我很抱歉这个长期的问题,但请耐心等待,我尽量让我的问题变得可以理解.如果你认为它可以更简洁随意编辑它.
我有一个客户端 - 服务器系统,客户端向服务器发送不同类型的请求,并根据请求获取响应.
客户端系统中的代码是:
int requestTypeA() {
Request request = new Request(TypeA);
Response response = request.execute();
// response for request of TypeA contains a int
return response.getIntResponse();
}
String requestTypeB() {
Request request = new Request(TypeB);
Response response = request.execute();
// response for request of TypeB contains a String
return response.getStringResponse();
}
Run Code Online (Sandbox Code Playgroud)
为了使上面的代码正确运行,Request
该类是:
class Request {
Type type;
Request(Type type) {
this.type = type;
}
Response execute() {
if (type == TypeA) {
// do stuff
return …
Run Code Online (Sandbox Code Playgroud) HTML 5具有新的数据属性data-*
鉴于以下用法:
<ul>
<li data-animal-type="bird">Owl</li>
<li data-animal-type="fish">Salmon</li>
<li data-animal-type="spider">Tarantula</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
我怎么能在Dart中访问这些属性.
我的for循环中的第一个print语句打印两次,然后再转到下一行.但是之后它会像之后那样贯穿循环?
我尝试使用我的调试器,但我以前从未使用它,我们没有在我的任何课程中使用它,我不太确定我在做什么
public static void main(String[] args)
{
int numElements;
Scanner keyboard = new Scanner(System.in);
System.out.println("How many people are you adding: ");
numElements = keyboard.nextInt();
ArrayBndQueue queue = new ArrayBndQueue<>(numElements + 1);
for(int index =0; index <= numElements; index++)
{
System.out.println("Enter a gender and name (ex: f jenny)");
String name = keyboard.nextLine();
System.out.println(name);
queue.enqueue(name);
}
}
Run Code Online (Sandbox Code Playgroud)