因此,只需执行以下操作即可轻松舍入十分之一:
int y;
double x = 2.5;
y = (int) (x+.5);
Run Code Online (Sandbox Code Playgroud)
但是在不使用 的情况下如何四舍五入到百分之几甚至千位呢Math.round()?
好吧,基本上我尝试使用url显示.gif,但它给了我一个空指针异常,我不知道为什么,因为我的url是正确的,我的代码没有其他问题(至少没有我能看到) .
import javax.swing.*;
import java.net.*;
public class image {
public image() {
}
public static void main(String[] args) {
URL url = image.class.getResource("<http://cdn.osxdaily.com/wp-content/uploads/2013/07/dancing-banana.gif>");
ImageIcon imageIcon = new ImageIcon(url);
JLabel label = new JLabel(imageIcon);
JFrame frame = new JFrame();
JPanel panel = new JPanel();
panel.add(label);
frame.add(panel);
frame.setTitle("Title");
frame.setSize(700,500);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
Run Code Online (Sandbox Code Playgroud)