怎么在java中导入txt,怎么在 运行参数中导入txt文件

如何在 运行参数中导入txt文件

刚开始crousera上学习

但对JAVA实在是不熟。

/*************************************************************************

*  Compilation:  javac ThreeSum.java

*  Execution:    java ThreeSum input.txt

*  Dependencies: In.java StdOut.java Stopwatch.java

*  Data files:   http://algs4.cs.princeton.edu/14analysis/1Kints.txt

*                http://algs4.cs.princeton.edu/14analysis/2Kints.txt

*                http://algs4.cs.princeton.edu/14analysis/4Kints.txt

*                http://algs4.cs.princeton.edu/14analysis/8Kints.txt

*                http://algs4.cs.princeton.edu/14analysis/16Kints.txt

*                http://algs4.cs.princeton.edu/14analysis/32Kints.txt

*                http://algs4.cs.princeton.edu/14analysis/1Mints.txt

*

*  A program with cubic running time. Read in N integers

*  and counts the number of triples that sum to exactly 0

*  (ignoring integer overflow).

*

*  % java ThreeSum 1Kints.txt

*  70

*

*  % java ThreeSum 2Kints.txt

*  528

*

*  % java ThreeSum 4Kints.txt

*  4039

*

*************************************************************************/

/**

*  The ThreeSum class provides static methods for counting

*  and printing the number of triples in an array of integers that sum to 0

*  (ignoring integer overflow).

*  

*  This implementation uses a triply nested loop and takes proportional to N^3,

*  where N is the number of integers.

*  

*  For additional documentation, see Section 1.4 of

*  Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

*

*  @author Robert Sedgewick

*  @author Kevin Wayne

*/

public class ThreeSum {

/**

* Prints to standard output the (i, j, k) with i 

* @param a the array of integers

*/

public static void printAll(int[] a) {

int N = a.length;

for (int i = 0; i 

for (int j = i+1; j 

for (int k = j+1; k 

if (a[i] + a[j] + a[k] == 0) {

StdOut.println(a[i] + " " + a[j] + " " + a[k]);

}

}

}

}

}

/**

* Returns the number of triples (i, j, k) with i 

* @param a the array of integers

* @return the number of triples (i, j, k) with i 

*/

public static int count(int[] a) {

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值