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

📄 util.java

📁 书籍《JAVA面向对象程序设计》书籍的课后源代码。相信对很多人都有帮助
💻 JAVA
字号:
///////    Util.java    ///////
package EDU.kent.cs.joop;
import java.io.*;
import java.text.*;
import javax.swing.*;
import java.util.Locale;


public class Util
{   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 + Util.EOL);
        afile.close();
    }

    // fields

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

}

⌨️ 快捷键说明

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