目标是找到大于n的最小数字,并且该数字的数字总和可以完全除以11.并且在我运行它之后,它什么都不返回。
public class M1
{
public static int nextCRC(int n)
{
int crc;
for (crc=n+1;crc!=0;crc++)
{
int sum=0;
for (crc =n+1 ; crc!=0; crc = crc / 10)
{
int digit = crc % 10;
sum += digit;
if ( sum %11 == 0)
{
break;
}
}
}
return crc;
}
public static void main(String[] args)
{
M1 Model=new M1();
Model.nextCRC(20);
System.out.println(Model.nextCRC(20));
}
}
答案 0 :(得分:-1)
你走了:
import java.math.*;
public class M1
{
public static int nextVal(int n)
{
int sum = 0;
int temp = n;
while(n>9){
sum = sum + n%10;
n = n/10;
}
sum = sum+n;
if((sum%11) == 0){
return temp;
}
return nextCRC(temp+1);
}
public static int nextCRC(int n) {
return nextVal(n+1);
}
public static void main(String[] args)
{
M1 Model=new M1();
Model.nextCRC(20);
System.out.println(Model.nextCRC(40));
}
}
答案 1 :(得分:-1)
这是我的解决方案:
select name,title,body from Users,Posts where Users.id=Posts.id group by Users.id