代碼如下:
package Decisions;
import java.util.Scanner;
public class CharactersTranverse {
//159,523
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Please enter a integer between 1,000 and 999,999:");
Scanner in = new Scanner(System.in);
String num = in.next();
in.close();
String result = "";
while(num.length() > 3){
result = num.substring(0, num.length()-4);
}
result = num + result;
System.out.println("The result is"+result);
}
}
結果:
在eclipse中撰寫完程式運行,輸入159,523.按下Enter鍵不顯示運行結果
uj5u.com熱心網友回復:
死回圈了兄弟,你在while里面debug一下,可以發現始終在回圈,因為你的num沒有改變,所以一直都是length = 7uj5u.com熱心網友回復:
你不如吧while改成if判斷,result 在回圈里也就賦值一次轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/195560.html
標籤:非技術區
下一篇:運行時報這個錯,是什么原因呢,
