我有java代码来计算数学公式,我想将它导出到Excel工作表,但是当我这样做时,计算得到的值变为+1而且我不知道如何解决这个问题,所以请你能帮助我们,下面你会看到我的代码行和屏幕截图从excl表中导出数据
public class Test {
public static void main(String[] args) {
double i = .5;
double x1 =1,x2=.001,x3=0.0005,c1=17.3387,c2=46.6885,c3=11.4775,c4=8.5316,c5=0.6561,c6=0.0907;
double deltakfuel,deltakamod,deltakcr = 0,deltak,xprim = 0;
System.out.println ("hello");
for (int t=0; t<2; t=t+1){
if ((t>0 & t<10)){
deltakcr = (i*1E-5/10)/t;
}
else if (t>60 & t<70){
deltakcr = (1E-5)*(i-8*(t-60));
} else
if (t<70){
deltakcr =-30E-5;
}
deltakfuel = -3.1E-5*x2+.0031E-5;
System.out.println("The value of DeltaKfuel = " +deltakfuel++);
deltakamod = -.6E-5*x3+.0003E-5;
System.out.println("The value of DeltaKmoderater = " +deltakamod++);
System.out.println("The value of DeltaKcontrol rod = " +deltakcr++);
deltak=deltakfuel+deltakamod+deltakcr;
System.out.println("The Total value of DeltaK = " +deltakcr++);
xprim = ((deltak/.001-6.502)*x1+.0124*c1+.0305*c2+.111*c3+.301*c4+1.14*c5+3.01*c6);
System.out.println("The total value of dn/dt = " +xprim++);
}
double dc1 = .21500*x1-.0214*c1;
double dc2= 1.424000*x1-0.0305*c2;
double dc3= 1.274000*x1-0.1110*c3;
double dc4= 2.568000*x1-0.3010*c4;
double dc5= 0.748000*x1-1.1400*c5;
double dc6= 0.273000*x1-3.0100*c6;
double dc7= 0.000200*x1-0.2000*x2;
double dc8 =0.000005*x1-0.0100*x3;
System.out.println("The value of dc1/dt = "+dc1++);
System.out.println("The value of dc2/dt = "+dc2++);
System.out.println("The value of dc3/dt = "+dc3++);
System.out.println("The value of dc4/dt = "+dc4++);
System.out.println("The value of dc5/dt = "+dc5++);
System.out.println("The value of dc6/dt = "+dc6++);
System.out.println("The value of dc7/dt = "+dc7++);
System.out.println("The value of dc8/dt = "+dc8++);
XSSFWorkbook workbook = new XSSFWorkbook();
//Create a blank sheet
XSSFSheet sheet = workbook.createSheet("Data");
//This data needs to be written (Object[])
Map<String, Object[]> data = new TreeMap<String, Object[]>();
data.put("1", new Object[] { "Value", "Value"});
data.put("2", new Object[] { ""+dc7, ""+dc7});
//Iterate over data and write to sheet
Set<String> keyset = data.keySet();
int rownum = 0;
for (String key : keyset)
{
Row row = sheet.createRow(rownum++);
Object [] objArr = data.get(key);
int cellnum = 0;
for (Object obj : objArr)
{
Cell cell = row.createCell(cellnum++);
if(obj instanceof String)
cell.setCellValue((String)obj);
else if(obj instanceof Integer)
cell.setCellValue((Integer)obj);
}
}
try
{
//Write the workbook in file system
FileOutputStream out = new FileOutputStream(new File("howtodoinjava_demo.xlsx"));
workbook.write(out);
out.close();
System.out.println("howtodoinjava_demo.xlsx written successfully on disk.");
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
这是java的输出
hello
The value of DeltaKfuel = 0.0
The value of DeltaKmoderater = 0.0
The value of DeltaKcontrol rod = -3.0E-4
The Total value of DeltaK = 0.9997
The total value of dn/dt = 2999.6999742299995
The value of DeltaKfuel = 0.0
The value of DeltaKmoderater = 0.0
The value of DeltaKcontrol rod = 5.000000000000001E-7
The Total value of DeltaK = 1.0000005
The total value of dn/dt = 3000.00047423
The value of dc1/dt = -0.15604817999999995
The value of dc2/dt = 7.500000001048335E-7
The value of dc3/dt = -2.4999999999053557E-6
The value of dc4/dt = -1.1599999999667432E-5
The value of dc5/dt = 4.599999999999049E-5
The value of dc6/dt = -6.999999999979245E-6
The value of dc7/dt = 0.0
The value of dc8/dt = 0.0
howtodoinjava_demo.xlsx written successfully on disk.
Excel output from java class showing that dc8/dt value became +1 from 0.0 to 1.0
答案 0 :(得分:0)
计算后有dc7++
和dc8++
。此variable++
操作会将变量递增1但返回原始值。