小编use*_*488的帖子

如何在没有 Math#round 的情况下进行舍入?

因此,只需执行以下操作即可轻松舍入十分之一:

int y;
double x = 2.5;

y = (int) (x+.5);
Run Code Online (Sandbox Code Playgroud)

但是在不使用 的情况下如何四舍五入到百分之几甚至千位呢Math.round()

java math

2
推荐指数
1
解决办法
2万
查看次数

尝试显示一个gif文件时java.lang.NullPointerException?

好吧,基本上我尝试使用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)

java swing nullpointerexception

-1
推荐指数
1
解决办法
289
查看次数

标签 统计

java ×2

math ×1

nullpointerexception ×1

swing ×1