java中100 0,为什么int exp1 = 14/20 * 100;在java中等于'0'?

I'm trying to do some basic math and it keeps popping up as 0. I'm sure it has to do with it being an int but I don't know how to work around it. I need to use integers but the math to arrive at those integers uses decimals. How do I do it?

解决方案

This is not special to blackberry, it's standard java behaviour.

This is because you're doing integer math:

int subexpr1 = 14 / 20; // 0

int subexpr2 = subexpr1 * 100; // 0

Use a double instead or change the order

int expr1 = (int) 14.0/20 * 100; // Very small possibility of rounding errors

int expr2 = 14 * 100 / 20; // Will ignore fraction parts

Java 使用 Oracle EXP 和 IMP 工具可以通过以下步骤完成: 1. 首先,在 Java 程序使用 Runtime 类的 exec() 方法启动命令行窗口或终端。 2. 然后,使用 Process 对象获取输出流和错误流,并将命令行参数传递给 Oracle EXP 或 IMP 工具。 3. 执行命令并等待命令完成。在命令完成后,可以检查输出流和错误流以获取任何错误信息。 以下是一个示例代码片段,演示如何在 Java 使用 Oracle EXP 和 IMP 工具: ``` import java.io.*; public class OracleExpImp { public static void main(String[] args) { try { // 启动命令行窗口或终端 Process process = Runtime.getRuntime().exec("cmd"); // 获取输出流和错误流 OutputStream outputStream = process.getOutputStream(); InputStream inputStream = process.getInputStream(); InputStream errorStream = process.getErrorStream(); // 执行命令并等待命令完成 String command = "exp userid=username/password@database file=export.dmp"; outputStream.write(command.getBytes()); outputStream.flush(); outputStream.close(); int exitCode = process.waitFor(); // 检查输出流和错误流以获取任何错误信息 BufferedReader inputReader = new BufferedReader(new InputStreamReader(inputStream)); String inputLine; while ((inputLine = inputReader.readLine()) != null) { System.out.println(inputLine); } inputReader.close(); BufferedReader errorReader = new BufferedReader(new InputStreamReader(errorStream)); String errorLine; while ((errorLine = errorReader.readLine()) != null) { System.err.println(errorLine); } errorReader.close(); if (exitCode != 0) { System.err.println("命令执行失败"); } } catch (IOException | InterruptedException e) { e.printStackTrace(); } } } ``` 此代码片段演示了将 Oracle EXP 工具用于导出数据库。要使用 Oracle IMP 工具进行导入,请更改命令参数和命令字符串。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值