我似乎无法找到一个关于一个简单问题的答案:如何将任何数字四舍五入到最近int?
例如,每当数字为0.2,0.7,0.2222,0.4324,0.9999时,我希望结果为1.
到目前为止我有
int b = (int) Math.ceil(a / 100);
Run Code Online (Sandbox Code Playgroud)
但它似乎并没有完成这项工作.
我希望能够替换空格,-但也想删除逗号和问号.我怎么能在一个函数中做到这一点?
到目前为止,我有它替换空格:
str_replace(" ","-",$title)
Run Code Online (Sandbox Code Playgroud) 我不想将任何参数传递给doInBackgroundAsyncTask的方法.
那么代码应该是什么样的呢?
我从git克隆了存储库A的主分支,并创建了自己的分支Li.我前段时间做了一些改动,把当地李的内容推到了偏远的李.
现在我已经从远程主机到本地主分支以及从本地主分支到本地Li的一些更新,我正在尝试将更新从本地Li推送到远程Li.但是,当我尝试运行时:
git checkout Li
git push origin Li
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
error: failed to push some refs to 'git@github.com:anodejs/system.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Run Code Online (Sandbox Code Playgroud)
请注意,我的本地主分支已更新(我调用了git pull origin master)并合并到本地Li分支.但是,我确实在本地Li添加了一个新文件,因此本地Li与本地主人不同(但这不应该,对吧?)
谢谢,李
比较StreamJava 8中的两个实例并找出它们是否具有相同的元素,特别是出于单元测试的目的,有什么好方法?
我现在得到的是:
@Test
void testSomething() {
Stream<Integer> expected;
Stream<Integer> thingUnderTest;
// (...)
Assert.assertArrayEquals(expected.toArray(), thingUnderTest.toArray());
}
Run Code Online (Sandbox Code Playgroud)
或者:
Assert.assertEquals(
expected.collect(Collectors.toList()),
thingUnderTest.collect(Collectors.toList()));
Run Code Online (Sandbox Code Playgroud)
但这意味着我正在构建两个集合并丢弃它们.考虑到我的测试流的大小,这不是性能问题,但我想知道是否有一种规范的方法来比较两个流.
我正在使用Java:The Complete Reference这本书学习Java.目前我正在研究Recursion主题.
请注意: stackoverflow上有类似的问题.我搜索了他们,但我没有找到我的问题的解决方案.我对以下程序中的逻辑感到困惑.
如果我运行以下程序,它会产生正确的输出,但我不明白逻辑.
我想你明白我被困在哪里/困惑.
谢谢.
Run Code Online (Sandbox Code Playgroud)class Calculation { int fact(int n) { int result; if(n==1) return 1; result = fact(n-1) * n; return result; } } public class Factorial { public static void main(String args[]) { Calculation obj_one = new Calculation(); int a = obj_one.fact(4); System.out.println("The factorial of the number is : " + a); } }
在Java中:是否是List.iterator()线程安全的,即返回的迭代器是在任何时候反映列表的当前状态还是仅在列表创建时反映列表的状态?
我用Eclipse Scala IDE编写了一个Scala程序,scala.util.parsing.JSON我希望将其转换为支持Scala 2.11版本.在Scala 2.11中我收到一个错误:
error: object parsing is not a member of package util.我发现默认情况下解析库不再出现在util包中,但必须在这里单独下载.
我已下载并尝试将其添加到我的Eclipse项目中作为新的源文件夹,但这没有用.这些说明仅用于将其添加到sbt,但如果我想在Eclipse中使用它,我认为这与我无关.
我应该尝试在某处找到JAR文件吗?
我有以下Java代码:
import java.util.concurrent.*;
class Foo{
static Semaphore s = new Semaphore(1);
public void fun(final char c, final int r){
new Thread(new Runnable(){
public void run(){
try{
s.acquire(r);
System.out.println(c+"_"+r);
s.release(r+1);
} catch(Exception e){ e.printStackTrace(); }
}
}).start();
}
}
class ths{
public static void main(String[]args) throws Exception{
Foo f = new Foo();
f.fun('B',2);
f.fun('F',6);
f.fun('A',1);
f.fun('C',3);
f.fun('D',4);
f.fun('E',5);
}
}
Run Code Online (Sandbox Code Playgroud)
理想情况下,这应按顺序打印A_1到F_6并退出,但由于某种原因不会发生.它通常打印A_1和B_2然后卡住.
我的代码找不到任何明显的错误.有什么建议?
抱歉我的英语不好.我正在尝试使用Android Studio将项目迁移到Gradle,但目前构建失败processDebugResources.
错误信息:
任务':app:processAdultDebugResources'的执行失败.java.io.FileNotFoundException:C:\ Projects\YYM\app\build\symbols\adult\debug\R.txt(系统找不到指定的文件.)(中文意思是"系统找不到文件")
另外,我发现在build我的项目路径中有R.java一个奇怪的路径下的文件:build/source/r/debug/--output-text-symbols.
这是我的一部分build.gradle:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.0.1'
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
versionCode 78
versionName "1.7.72"
ndk {
abiFilters "armeabi"
}
}
productFlavors {
weightloss {
packageName "com.yesudoo.yymweightloss"
}
adult {
packageName "com.yesudoo.yymadult"
}
}
buildTypes {
debug {
packageNameSuffix ".dev"
versionNameSuffix "-dev"
}
}
lintOptions {
abortOnError false
}
}
Run Code Online (Sandbox Code Playgroud)
我是Gradle的新手,并提前感谢任何关于如何解决这个问题的指示.