我正在尝试使用线程建立一种计时机制,但在获取两个日期之间的时差并使用该时差获取当前剩余时间百分比时遇到了问题。这是我要尝试原型化的概念:

这是我的实现:
long startMilisecs = System.currentTimeMillis();
long currentMilisecs;
long endDateMilisecs = getEndDate().getTime();
int diffMillisecs = ((int)(endDateMilisecs - startMilisecs) / 1000) / 60;
int currPerc;
while (startMilisecs <= endDateMilisecs)
{
currentMilisecs = (int) System.currentTimeMillis();
currPerc = ((int)currentMilisecs * 100) / diffMillisecs;
System.out.println(" Current Percentage: " + currPerc);
}
Run Code Online (Sandbox Code Playgroud)
此代码的问题在于百分比不是从0开始,而是从20到40%。
你能告诉我这是怎么了吗?对于这个问题,我只能使用线程。
public class TestVO {
public static void main(String[] args) {
VO vo1 = new VO();
VO vo2 = new VO();
VO vo3;
VO vo4 = new VO();
vo1.setName("Sourav");
vo2.setName("Anil");
vo3 = vo1;
vo4 = vo1;
System.out.println(" " + vo4.getName());
vo1.setName("Abhishek.");
System.out.println(vo1.getName() + " " + vo2.getName() + " " + vo3.getName() + " " + vo4.getName());
}
}
Run Code Online (Sandbox Code Playgroud)
--OUTPUT是:---
Sourav
Abhishek. Anil Abhishek. Abhishek.
Run Code Online (Sandbox Code Playgroud)
VO是一个包含String名称的简单类 ,包含getter和setter.
在第一个System.out.println*vo4.getName()*print:Sourav ok.It没关系.
但在第二个 …
在谷歌代码上找到的一些库中,我遇到了这个util方法:
public static void gc(){
Object obj = new Object();
WeakReference ref = new WeakReference<Object>(obj);
obj = null;
while(ref.get()!=null)
System.gc();
}
Run Code Online (Sandbox Code Playgroud)
它的doc说它提供了一种调用GC的可靠方法,因为调用System#gc()只是一个没有任何保证的提示.我把它展示给了我的大四学生,他说我应该考虑为什么这种方法无效.我读了一些关于弱引用的文章,但我仍然感到困惑.有人能告诉我这一点吗?
我使用php复选框,我想检索标记值.
我的复选框代码:
<label for="cours">Je suis intéressé par un ou plusieurs cours :</label><br><br>
<input type="checkbox" name="cours" value="individuel">Individuel<br>
<input type="checkbox" name="cours" value="semiprive">Semi-privé<br>
<input type="checkbox" name="cours" value="minigroupe">Mini-groupe<br>
<input type="checkbox" name="cours" value="intensif">Intensif<br>
<input type="checkbox" name="cours" value="entreprise">Entreprises<br>
<input type="checkbox" name="cours" value="distance">A distance<br>
<input type="checkbox" name="cours" value="telephone">Par téléphone<br>
<input type="checkbox" name="cours" value="coaching">Coaching<br>
<input type="checkbox" name="cours" value="soutien">Soutien scolaire<br>
<input type="checkbox" name="cours" value="diplome">Diplômes officiels<br>
Run Code Online (Sandbox Code Playgroud)
php:
<?php
if(isset($_POST['envoyer']))
{
if(get_magic_quotes_gpc())
{
$cours = stripslashes(trim($_POST['cours']));
}
}
?>
Run Code Online (Sandbox Code Playgroud)
我想把它放在变量msg中:
$msg = 'Cours : '.$cours."\r\n";
Run Code Online (Sandbox Code Playgroud)
并发送消息抛出php电子邮件功能.
但是,当我这样做的时候,只收到第一个选中的选项......
谢谢你的帮助.
迈克尔
我正在做一个bash脚本,我想显示变量的字符($ VAR).我希望脚本做的是(伪代码):
String var = "Hello";
for (int i = 0; i < var.length(); i++) {
System.out.println(var.substring(i, i+1));
}
变量的大小可以改变,一次可以是5个字符,下一次是6.谢谢你的帮助!迈克尔 我正在使用SuggestBox,我在获取应用程序的良好行为方面遇到了一些困难.
请考虑以下建议列表:
1. lol 2. good evening 3. goodbye 4. end 5. saluti
如果我将我的SuggestBox与此列表一起使用并输入"g",我将获得:
1. good evening 2. goodbye
我键入"e":
1. good evening 2. end
但我想要获得的是包含输入的单词,而不仅仅是以输入开头的单词.例如,如果我输入"l",我想获得:
1. lol 2. saluti
而且不仅:
1. lol
我怎样才能解决这个问题?
谢谢您的帮助.
代码末尾的分号(;)是让我迷失的东西.
private View.OnClickListener onSave = new View.OnClickListener() {
public void onClick(View v) {
EditText name=(EditText)findViewById(R.id.name);
EditText address=(EditText)findViewById(R.id.addr);
r.setName(name.getText().toString());
r.setAddress(address.getText().toString());
}
};
Run Code Online (Sandbox Code Playgroud) 我在图像视图上生成饼图,我想通过电子邮件发送它.
如何将图像视图的图像转换为电子邮件附件,因为它在资源中不可用?
我想加载一个网页.
private class MyJavaScriptInterface {
private MyJavaScriptInterface () {
}
public void setHtml(String contentHtml) {
if (contentHtml != null && contentHtml.trim().length() > 0) {
//Do something
}
}
}
private WebViewClient webViewClient = new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
view.loadUrl("javascript:window.ResponseChecker.setHtml"
+ "(document.body.innerHTML);");
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
}
public void onReceivedSslError(WebView view, SslErrorHandler handler,
SslError error) {
handler.proceed();
}
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Log.e("ProcessPayment", …Run Code Online (Sandbox Code Playgroud)