尝试创建一个打印数组最高元素的递归函数.
它说,它需要;之前else maxi=xs.head和}之后max(xs.tail)
我不认为scala使用半冒号,你何时应该使用它们以及其他一些基本的句法规则.
var maxi = 0
def max(xs: List[Int]): Int = {if (xs.isEmpty) throw new java.util.NoSuchElementException()
else if (xs.tail.isEmpty) maxi
else if (xs.tail.head > xs.head) maxi = xs.tail.head
max(xs.tail)
else maxi=xs.head
max(xs.tail)
}
Run Code Online (Sandbox Code Playgroud) 美好的一天!我在获取java线程的内存使用方面遇到了麻烦.我的研究把我带到了ThreadMxBean库.根据javadocThreadMXBean#setThreadAllocatedMemoryEnabled,应该有一个getThreadAllocatedBytes允许获取线程内存的方法.但是,我找不到这种类的方法,而存在上述文档中描述的其他方法.
示例getCurrentThreadCpuTime()并isThreadCpuTimeEnabled()显示在我的代码中.
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import javax.management.AttributeNotFoundException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
import javax.management.MalformedObjectNameException;
import javax.management.ReflectionException;
class TwoThreadsTest {
public static void main (String[] args) throws Exception {
new Coding("Jamaica").start();
ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
long b = threadBean.getCurrentThreadCpuTime();
boolean bool= threadBean.isThreadCpuTimeEnabled();
System.out.println(bool);
}
}
Run Code Online (Sandbox Code Playgroud) public Void doInBackground()
Run Code Online (Sandbox Code Playgroud)
void 当我希望以小盘头看到它时,它是资本化的.
后来在同样的方法中,我看到return null;哪个让我想知道Void是一个类似于整数,字符等的类.
谁能证实这个理论?
如果Void是一个类,什么时候会被使用?
我的教科书中有一个问题:
编写一个方法倍数,它将两个整数作为参数,如果第一个整数可以被第二个整数均分,则返回true(即,除法后没有余数); 否则,该方法应返回false.将此方法合并到一个应用程序中,使用户可以输入值来测试方法.
我写了这段代码,但它不起作用:
public class project1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int a, b;
System.out.println("enter the first number");
a = input.nextInt();
System.out.println("enter the first number");
b = input.nextInt();
}
public static boolean multiple(int g, int c) {
int g, c;
if (g % c = 0) {
return true;
} else {
return false;
};
}
}
Run Code Online (Sandbox Code Playgroud) 我想要匹配 [#ABABAB]blah blah blah[/#ABABAB]
但我不想匹配 [#ABABAB]blah blah blah[/#000000]
ABABAB和000000是十六进制颜色代码.
第一个是我想要的,因为它的开放标签和关闭标签的颜色代码是相同的,但第二个不是.
我尝试过这种模式,但它不起作用: \[#[0-9|A-F]{6}\].*\[/#[0-9|A-F]{6}\]
package com.spse.pricing.client.main;
import java.util.stream.IntStream;
public class NestedParalleStream {
int total = 0;
public static void main(String[] args) {
NestedParalleStream nestedParalleStream = new NestedParalleStream();
nestedParalleStream.test();
}
void test(){
try{
IntStream stream1 = IntStream.range(0, 2);
stream1.parallel().forEach(a ->{
IntStream stream2 = IntStream.range(0, 2);
stream2.parallel().forEach(b ->{
IntStream stream3 = IntStream.range(0, 2);
stream3.parallel().forEach(c ->{
//2 * 2 * 2 = 8;
total ++;
});
});
});
//It should display 8
System.out.println(total);
}catch(Exception e){
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
请帮助如何自定义并行流,以确保我们得到一致性结果。
//Pylons
int xCoord[];
int yCoord[];
int numSquare;
boolean firstPaint;
public void init() {
//Images Call
pylon = getImage(getDocumentBase(), "image/pylon.png");
numClicks = 0;
//pylons
xCoord = new int[100];
yCoord = new int[100];
numSquare = 0;
}
public void paint(Graphics g) {
if (numClicks == 0) {
drawUI(g);
//probeDraw(g,2);
}
if (numSquare == 1) {
for (int k = 0; k < numSquare; k++) {
g.drawImage(pylon, xCoord[k], yCoord[k], this);
}
Minerals -= 100;
popMax += 9;
}
}
public boolean mouseDown(Event e, …Run Code Online (Sandbox Code Playgroud) 嗨有一个名为read.txt的文件,下面是文件内的数据.
OS:B,A,Linux,Windows 7,Windows
ARCH:32 Bit,64 Bit
Browser:Chrome,Firefox,IE
Run Code Online (Sandbox Code Playgroud)
我想读取该文件,并希望通过使用
":"符号拼写将数据存储到每个列的String数组中.
示例如下
String a[] = { "A","B","Linux", "Windows 7", "Windows" };
String b[] = { "32 Bit", "64 Bit"};
String c[] = { "Chrome", "Firefox" ,"IE"};
Run Code Online (Sandbox Code Playgroud)