小编use*_*451的帖子

从Java中读取文件时的空值

所以,我试图在java中读取一个文件.该文件只包含一行,是一组由星号分隔的设置.

计划是使用.split方法将它们解析为数组,并将每个数组索引分配给正确的变量.

不幸的是,虽然我的文件显然是存在的,但是它为输出返回一个空值,这是不正确的.

这是我的代码:

try {
        try {
            /* Create and display the form */
            Class.forName("com.mysql.jdbc.Driver").newInstance();
        } catch (    InstantiationException | IllegalAccessException ex) {
            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
       Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, "Loaded okay.");
   } catch (ClassNotFoundException ex) {
       Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
   }
    java.awt.EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            new JFrame().setVisible(true);
        }
    });

    String s = System.getenv("APPDATA");
    File f = new File(s + "\\TinyboardMod\\settings.txt");
    if(f.exists() && !f.isDirectory()) {
        BufferedReader br = new BufferedReader(new FileReader(f));
        String line;
        while ((line = br.readLine()) != …
Run Code Online (Sandbox Code Playgroud)

java

0
推荐指数
1
解决办法
720
查看次数

C#阶乘计算器无法正常工作

我的阶乘计算器工作不正常.

正如我的教授想要的那样,它的预期工作时间为1到20.但是,输入0应该返回1的阶乘; 它返回0

这是我的代码:

        private void CalculateFactorial(long number)
    {
        //perform the calculations
        long result = number;
        for (int i = 1; i < number; i++)
        {
            result = result * i;
        }

        //display the calculated Factorial to the user
        txt_Factorial.Text = result.ToString("n0");
    }
Run Code Online (Sandbox Code Playgroud)

以下是调用上述方法的方法,即compute计算按钮的事件处理程序:

private void btn_Calculate_Click(object sender, EventArgs e)
    {
        //get the users input
        long number = long.Parse(txt_Number.Text);

        // make sure the number not invalid. If it is invalid, tell the user
        // otherwise, proceed to calculation. 
        if (number …
Run Code Online (Sandbox Code Playgroud)

c# math factorial

0
推荐指数
1
解决办法
454
查看次数

标签 统计

c# ×1

factorial ×1

java ×1

math ×1