以下是我的代码,我尝试使用BigInteger inn Java计算从1到100的所有数字的LCM.但它没有提供任何答案.
import java.math.BigInteger;
public class CommonOneToHundred {
public static void main(String[] args) {
// TODO Auto-generated method stub
BigInteger res =new BigInteger("1");
int i = 2;
while(i<=100){
res = lcm(res,BigInteger.valueOf(i));
i++;
}
System.out.println(res);
}
static BigInteger lcm(BigInteger x, BigInteger y)
{
BigInteger a;
//a = (x > y) ? x : y; // a is greater number
a = y;
while(true)
{
if(a.divide(x).equals(0) && a.divide(y).equals(0))
return a;
a = a.add(BigInteger.ONE);
}
}
}
Run Code Online (Sandbox Code Playgroud)
将值插入数据库,正确插入整数值,但字符串值被某些垃圾值替换.
使用%s或%q作为字符串的占位符.
int sl_no1 = sl_no;
int ac_no1 = account_no;
string u_name = name;
string u_add = address;
int u_bal = bal;
cout<<sl_no1<<endl<<ac_no1<<endl<<u_name<<endl<<u_add<<endl<<u_bal;
/** Create SQL statement */
//sql = "INSERT INTO ACCOUNT (SL_NO,ACCOUNT_NO, NMAE, ADDRESS, BALANCE) VALUES (" << sl_no1 <<", '"<< ac_no1 <<",'" << u_name <<", '"<< u_add <<", '" << u_bal << "')";
sql = sqlite3_mprintf("INSERT INTO ACCOUNT VALUES('%d','%d','%q','%q','%d' )", sl_no1,ac_no1,u_name, u_add, u_bal);
/** Execute SQL statement */
rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
if( rc …Run Code Online (Sandbox Code Playgroud)