我想找到包含一些文本的文件,但应该以某个字符开头。
grep -inr "my text" .
Run Code Online (Sandbox Code Playgroud)
上述命令将显示包含上述文本的所有文件。但我想要的是文件是否包含文本并且名称应以 E* 开头。
setUpand (前置条件和后置条件设置)是teardown由名称setUp()and标识teardown()还是由@Beforeand标识@After?
换句话说,JUnit 中是否可以有 a@Before teardown()和 a @After setUp()?
Scanner input = new Scanner(System.in);
Random random = new Random();
System.out.print("Enter a number u wish(1-1000): ");
int unos = input.nextInt();
int rand = random.nextInt(1000) + 1;
System.out.println(rand);
if (unos = random) {
System.out.printf("Congratz u won");
}
while (unos < rand) {
System.out.println("Your number is lower \t Try again: ");
unos = input.nextInt();
}
while (unos > rand) {
System.out.println("Your number is higher\t Try again: ");
unos = input.nextInt();
}
Run Code Online (Sandbox Code Playgroud)
所以,如果我点击的数字不等于随机生成的数字,那么一旦我点击,它就不会输出"Congratz u won".它终止了.为什么?
import java.util.Scanner;
import java.util.Random;
public class Lutrija { …Run Code Online (Sandbox Code Playgroud) 我必须使用 GuavaLoadingCache将 xpath 表达式缓存为 xpath 值。
问题在于并非所有 xpath 都有值。大多数时候该值为null.
代码片段:
private LoadingCache<String, List<String>> cachedXpaths = CacheBuilder.newBuilder()
.expireAfterWrite(3, TimeUnit.MINUTES)
.maximumSize(1000)
.concurrencyLevel(5)
.weakKeys()
.build(new CacheLoader<String, List<String>>() {
@Override
public List<String> load(String key) throws Exception {
return createListByKey(key);
}
});
private static List<String> createListByKey(String key) throws Exception {
List<String> values = null;
try {
values = instance.getXpathValues(key);
} catch (XPathExpressionException ignore) {
}
return values;
}
Run Code Online (Sandbox Code Playgroud)
结果:
testEncounterSection(com.epam.cdatest.section.EncountersSectionTest) Time elapsed: 0.002 sec <<< FAILURE!
com.google.common.util.concurrent.UncheckedExecutionException: com.epam.cdatest.exceptions.XpathHasEmptyValueException
at com.epam.cdatest.parsers.XpathEvaluator.getXpathValues(XpathEvaluator.java:123)
at …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的列表:
["1", "8", "9", "5", "6"]
Run Code Online (Sandbox Code Playgroud)
并希望将其转换为单个整数.所以期望的输出是这样的:18956
有一个优雅的方法来做到这一点?
进入我脑海的唯一方法是通过列表并将数字乘以所需的10的幂并将所有数据相加.但我相信有更好的方法,不是吗?谢谢你的帮助.