Eclipse普通java Project文件路径问题
项目的结构如图
读取src里某个包下的文件,代码如下
BufferedReader br=new BufferedReader(new FileReader("src/ch01/practice1/input.txt"));
输出到同一目录下,代码如下
PrintWriter pw=new PrintWriter("src/ch01/practice1/output.txt");
整个算法代码如下
package ch01.practice1;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
//import java.util.Arrays;
//统计数字问题
public class PageNuber
{
public static void main(String[] args) throws IOException
{
BufferedReader br=new BufferedReader(new FileReader("src/ch01/practice1/input.txt"));
String line=br.readLine();
if (null!=line)
{
int n=Integer.valueOf(line);
int[] arr= new int[10];
// Arrays.fill(arr,0);
// System.out.println(Arrays.toString(arr));
for (int i = 1; i < n+1; i++)
{
int div=i;
while(div>0)
{
arr[div%10]++;
div=div/10;
}
}
// System.out.println(Arrays.toString(arr));
PrintWriter pw=new PrintWriter("src/ch01/practice1/output.txt");
for (int i = 0; i < arr.length; i++)
{
pw.print(arr[i]+" ");
}
pw.close();
}
br.close();
}
}
原文地址:https://www.cnblogs.com/linkchen/p/12368214.html
时间: 2024-10-09 13:53:07