我想打印两个数字之间的所有素数.这是我的代码:
package sphere;
import java.math.BigInteger;
import java.io.*;
class PrimeTest2 {
public static void main(String args[]) throws java.lang.Exception {
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
String s = r.readLine();
String [] splitted = s.split(" ");
BigInteger lower = new BigInteger(splitted[0]);
BigInteger upper = new BigInteger(splitted[1]);
int lowerAsInt = Integer.parseInt(splitted[0]);
int upperAsInt = Integer.parseInt(splitted[1]);
BigInteger intermediate = lower;
for (int i=lowerAsInt; i<upperAsInt; i++) {
intermediate = intermediate.nextProbablePrime();
System.out.println(intermediate);
}
}
}
Run Code Online (Sandbox Code Playgroud)
当它以1 10运行时,输出为:
2
3
5
7
11
13
17
19
23 …Run Code Online (Sandbox Code Playgroud) 对于加载5100个素数然后迭代它们的任务,最好的数据结构(在java中)是什么?
例如,我需要知道在1000000000和相同数字减去100000之间的素数.
考虑以下代码:
class Jm44 {
public static void main(String args[]){
int []arr = {1,2,3,4};
for ( int i : arr )
{
arr[i] = 0;
}
for ( int i : arr )
{
System.out.println(i);
}
}
}
Run Code Online (Sandbox Code Playgroud)
它打印:
0
0
3
0
Run Code Online (Sandbox Code Playgroud)
这是什么?For-each应该运行在数组中的所有元素,为什么它会运行arr[3]=0但不会arr[2]=0?
我创建了这个愚蠢的程序来玩 wait()
public class WaitTest {
public static void main(String [] args) {
System.out.print("1 ");
synchronized(args){
System.out.print("2 ");
try {
args.wait();
args.notifyAll();
}
catch(InterruptedException e){ System.out.print("exception caught");}
System.out.print("3 ");
}
}
}
Run Code Online (Sandbox Code Playgroud)
在我的机器上,代码永远不会打印3,除非我写wait(100)或其他毫秒数.为什么是这样?
鉴于此代码:
public class TwoThreads {
static Thread laurel, hardy;
public static void main(String[] args) {
laurel = new Thread() {
public void run() {
System.out.println("A");
try {
hardy.sleep(1000);
} catch (Exception e) {
System.out.println("B");
}
System.out.println("C");
}
};
hardy = new Thread() {
public void run() {
System.out.println("D");
try {
laurel.wait();
} catch (Exception e) {
System.out.println("E");
}
System.out.println("F");
}
};
laurel.start();
hardy.start();
}
}
Run Code Online (Sandbox Code Playgroud)
输出包括:
A C D E and F
Run Code Online (Sandbox Code Playgroud)
我很困惑为什么包含F,因为IllegalMonitorStateException在synchronized代码之外调用wait()时会抛出一个.为什么达到F的印刷声明?我相信线程堆栈随后会爆炸,但程序应该将控制传递给它的主堆栈.
它是否正确?
我无法为这个自动机构建过渡函数.
我想我应该为每个a堆叠一个1并为每个b取出堆栈
c的数量等于ab对的数量,所以我想我应该为每个遇到的b堆叠一个0.事情是:我如何取消堆叠1并同时添加0?
我正在尝试从Learn You a Haskell for Great Good中编译这个函数.
removeNonUppercase st = [ c | c <- st, c `elem` ['A'..'Z']]
Run Code Online (Sandbox Code Playgroud)
将它放入removeNonUpperCase.hs文件中.
编译很好,但在传递参数时:
ghci> removeNonUppercase "Hahaha! Ahahaha!"
Run Code Online (Sandbox Code Playgroud)
编译器说:
<interactive>:1:0: Not in scope: 'removeNonUpperCase'
Run Code Online (Sandbox Code Playgroud)
为什么?
PrintScreen:http://img535.imageshack.us/img535/9545/notinscope.png
我想available_seats在FLIGHT每次向FLIGHT_PLAN表中添加新行条目时自动减少表中的值
FLIGHT_PLAN 定义为:
FLIGHT_PLAN (plan_number NUMBER, flight_number NUMBER)
Run Code Online (Sandbox Code Playgroud)
并被FLIGHT定义为
FLIGHT (flight_number NUMBER, available_seats NUMBER)
Run Code Online (Sandbox Code Playgroud)
我应该使用存储过程,触发器吗?
用gcc编译这段代码时
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
typedef struct _Nodo
{
unsigned int id_thread;
int id_mutex;
_Nodo *solicita;
_Nodo *asignado;
}Nodo;
Run Code Online (Sandbox Code Playgroud)
我明白了:
libdrm.c:13: error: expected specifier-qualifier-list before ‘_Nodo’
Run Code Online (Sandbox Code Playgroud)
为什么?
我正在写一个数独的回溯解算器,它已经卡住了,我不明白为什么.我认为我的递归调用没问题.我错过了什么?
输入从input.txt文件中读取,网格初始布局在一行中:
input.txt中:
004020000201950070090004852005490001006000900800051300958100020010072608000080500
Run Code Online (Sandbox Code Playgroud)
编辑:我的意思是"卡住",因为没有完成它对网格的解决
这是一个示例输出:
current move count is 6
3 6 4 7 2 8 1 9 0
2 0 1 9 5 0 0 7 0
0 9 0 0 0 4 8 5 2
0 0 5 4 9 0 0 0 1
0 0 6 0 0 0 9 0 0
8 0 0 0 5 1 3 0 0
9 5 8 1 0 0 0 2 0
0 1 0 0 7 2 …Run Code Online (Sandbox Code Playgroud)