⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myutil.java.bak

📁 本“计算器”可以完成任意的通常借助手持计算器来完成的标准运算。“计算器”可用于基本的算术运算
💻 BAK
字号:
///////    MyUtil.java    ///////
import java.io.*;
import java.text.*;
import javax.swing.*;
import java.util.Locale;

public class MyUtil
{   public static String doubleFormat(double p, String format)
    {  Locale us = new Locale("en", "US");
       NumberFormat nf =
         NumberFormat.getNumberInstance(us);
       DecimalFormat df = (DecimalFormat)nf;
       df.applyPattern(format);
       return df.format(p);
    }

    public static boolean validInt(String s, int len)
    {  int i = s.length();
       if ( i  > len ) return false;
       String digits = "0123456789";
       for (int j=0; j < i; j++)
       {   if ( digits.indexOf(s.charAt(j)) < 0 )
           return false;
       }
       return true;
    }

    public static boolean validSS(String ss)
    {  int i = ss.length();
       String digits = "0123456789";
       if ( i != 9 ) return false;
       for (int j=0; j < i; j++)
       {   if ( digits.indexOf(ss.charAt(j)) < 0 )
           return false;
       }
       return true;
    }

    public static void errorDialog(JFrame f, String msg)
    {   JOptionPane.showMessageDialog(f, msg,
                    "Error Message",
                     JOptionPane.ERROR_MESSAGE);
    }

    public static BufferedReader getBufferedReader(InputStream in)
    {   return (new BufferedReader (new InputStreamReader(in)));
    }

    public static String getInput(String prompt)
          throws IOException
    {   
        BufferedReader in = new BufferedReader
                (new InputStreamReader(System.in));
        System.out.print(prompt + " = "); 
        System.out.flush();
        String s = in.readLine();
        if ( s != null && s.length() != 0) return s;
        return getInput(prompt);
    }

    public static void appendToFile(String file, String line)
               throws IOException
    {   RandomAccessFile afile = 
             new RandomAccessFile(file,"rw");
        if ( afile != null )
           afile.seek(afile.length());  
        else
           throw(new IOException());
        afile.writeBytes(line + MyUtil.EOL);
        afile.close();
    }

    // fields

    public static String EOL = System.getProperties().
                      getProperty("line.separator");

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -