算法錯(cuò)誤 求助求助
package test1;
public class test2
{
?? ?public static void main(String args[])
?? ?{
?? ??? ?int mul = 1;
?? ???? int num = 999;
?? ???? int count = 0;
?? ???? for(int i=9;i>=1;i--)
?? ???? {
?? ??? ??? ?for (int j=1;j<=i;j++)
?? ??? ??? ?{
?? ??? ??? ??? ?mul=mul*10;
?? ??? ??? ?}
?? ??? ??? ?count=num/mul;
?? ??? ??? ?if (count!=0)
?? ??? ??? ?{
?? ??? ??? ??? ?System.out.println(mul+1);
?? ??? ??? ??? ?break;
?? ??? ??? ?}?? ??? ?
?? ???? }
?? ?}
}
這個(gè)代碼提示有除0錯(cuò)誤,求助?。。?!
2015-12-01
if (num >= 0 ?&& num<=999999999){
? ? ?while(num != 0){
? ? ?count++;
? ? ?num/=10; ? ?// num/=10的意思是將整數(shù)num末尾數(shù)去掉,可用于計(jì)算一個(gè)數(shù)字的位數(shù)。
? ? ?}
System.out.println("它是個(gè)"+ count+"位的數(shù)!");
} else{
System.out.println("輸入有誤!");
}
2015-11-22
int全部改為long
可以查一下int的取值范圍