让我们假设我们想要恢复以下字符串"áe".
这个unicode是"\ u0061\u0301\u0065".
恢复它的天真的方法将是char的char
private static String reverseStringNaive(String s) {
char[] characters = new char[s.length()];
for (int i = s.length() - 1; i >= 0; i--) {
int j = s.length() - i - 1;
characters[j] = s.charAt(i);
}
return new String(characters);
}
Run Code Online (Sandbox Code Playgroud)
当我们希望获得"eá"(\ u0065\u0061\u0301)时,它给了我们"éa"(\ u0065\u0301\u0061).精确的"'"应该与"a"结合在一起,而不是改为"e".
以下代码为我提供了该String的预期结果:
private static String reverseString(String s) {
char[] characters = new char[s.length()];
for (int i = s.length() - 1; i >= 0; i--) {
int j = s.length() - i - 1;
if (Character.isLetterOrDigit(s.charAt(i)) …Run Code Online (Sandbox Code Playgroud) 我正在尝试针对W3C XML Schema验证XML.
以下代码执行作业并报告发生错误的时间.但是我无法得到错误的行号.它总是返回-1.
有没有简单的方法来获得行号?
import java.io.File;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import org.w3c.dom.Document;
import org.xml.sax.SAXParseException;
public class XMLValidation {
public static void main(String[] args) {
try {
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = parser.parse(new File("myxml.xml"));
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Source schemaFile = new StreamSource(new File("myschema.xsd"));
Schema schema = factory.newSchema(schemaFile);
Validator validator = schema.newValidator();
validator.validate(new DOMSource(document));
} catch (SAXParseException e) {
System.out.println(e.getLineNumber());
e.printStackTrace();
} catch (Exception …Run Code Online (Sandbox Code Playgroud) 如何在使用jquery和blockUI插件加载页面时阻止UI?如果使用AJAX调用加载页面我知道解决方法,但是当页面加载回发时,如何阻止ui直到页面完全加载完成?
请帮忙.非常感谢您的努力和时间.
我从文件中读取了编码为"UTF-8"的字符串.我需要将它与表达式相匹配.文件的第一个字符是#,但在字符串中第一个是''(空符号).我用charset"UTF-8"把它翻译成字节,就在这里[-17, -69, -65].有谁知道它是什么以及如何用正则表达式解决它?
我有一个使用Spring Boot构建的简单微服务。它包含一个计划任务,我需要保留下一个计划任务的上一个计划任务日期。由于该服务将由于更新或任何意外原因而停止,请告知在本地存储此值的最佳实践是什么?谢谢
所以我一直在尝试为我的firend做一个python程序,我做了(加入了两个不同的密码),并且我一直试图让每次打开和关闭程序时都很容易加密不同的字符串.我在64位Windows 7计算机上使用python 3.2.
这是我的代码(请同时给我一些改进的提示):
#!/usr/bin/python
#from string import maketrans # Required to call maketrans function.
print ("Welcome to the Rotten Bat encription program. Coded in python by Diego Granada")
answer = input("Please enter the password: ")
if answer == 'raindrops':
print("Password accepted")
else:
print ("Incorrect password. Quiting")
from time import sleep
sleep(3)
exit()
intab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
outtab = "N9Q2T1VWXYZ7B3D5F8H4JK60n9pq2st1vwxyz7b3d5f8h4jk60"
message = input("Put your message here: ")
print(message.translate(dict((ord(x), y) for (x, y) in zip(intab, outtab))))
print ("Thank you for using this …Run Code Online (Sandbox Code Playgroud) 我有一个希望打印值的代码示例。正如我在 countDownLatch.countDown(); 之后的 run 方法中所想的那样 被称为 CountDownLatch 应该达到零并且 main 方法应该终止,但它没有发生。我错过了什么吗?
public class ExecutorWithCountDownLatch {
public static void main(String[] args) throws InterruptedException {
final ExecutorService executorService = Executors.newSingleThreadExecutor();
final CountDownLatch countDownLatch = new CountDownLatch(1);
executorService.execute(new ThreadCounter(countDownLatch));
countDownLatch.await(5, TimeUnit.SECONDS);
}
private static class ThreadCounter implements Runnable {
private CountDownLatch countDownLatch;
public ThreadCounter(CountDownLatch countDownLatch) {
this.countDownLatch = countDownLatch;
}
@Override
public void run() {
for (int i = 0; i <= 25; i++) {
System.out.println("printing numbers: " + i);
}
countDownLatch.countDown();
}
} …Run Code Online (Sandbox Code Playgroud)