日期:2014-05-20 浏览次数:20856 次
package class1; public class Number { /** * @param args */ public static void main(String[] args) throws Exception { // TODO Auto-generated method stub int[] number = new int[10]; int in, n; java.io.File file1 = new java.io.File( "D:\\Homeworks\\eclipse work place\\SuanFa\\src\\class1\\input.txt"); java.util.Scanner input = new java.util.Scanner(file1); int page = input.nextInt(); for (int i = 1; i <= page; i++) { n = i; while (n >= 0) { in = n % 10; number[in]++; n = n / 10; } } java.io.File file2 = new java.io.File( "D:\\Homeworks\\eclipse work place\\SuanFa\\src\\class1\\output.txt"); if (file2.exists()) { System.out.println("File2 already exists"); System.exit(0); } java.io.PrintWriter output = new java.io.PrintWriter(file2); for (int j = 0; j <= 9; j++) { output.println("number " + j + " " + number[j]); } input.close(); output.close(); } }