0
所以我想解決的HackerRank(項目歐拉Q1)link here這個問題,並已用下面的代碼來解決它HackerRank說〜在標準輸出上沒有任何反應〜
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
int T = 0;
ArrayList<Integer> N = new ArrayList<Integer>();
String[] Input = args;
if (args.length>1){
T = Integer.parseInt(args[0]);
if(T<1||T>Math.pow(10,6))
System.exit(0);
}
if (args.length-1 == T){
for (int i=1;i<args.length;i++){
N.add(Integer.parseInt(args[i]));
int sum3=0,sum5=0,sum15=0;
int count=0;
while (count<N.get(i-1)){
sum3+=count;
count+=3;
}
count =0;
while (count<N.get(i-1)){
sum5+=count;
count+=5;
}
count =0;
while (count<N.get(i-1)){
sum15+=count;
count+=15;
}
N.set(i-1,(sum3+sum5-sum15));
}
}
for(int j=0;j<N.size();j++)
System.out.println(N.get(j));
}
}
這給了我下面的輸出上IDE:
23
2318
在輸入:
2
10
100
而這個比賽日在HackerRankË預期的輸出,但然而,當我在網站上使用此代碼,它說:
輸入(stdin)
2
10
100
你的輸出(stdout)
~ no response on stdout ~
的預期輸出
23
2318
編譯消息
Wrong Answer
我可以觀察到的一件事是我無法在HackerRank的循環內打印任何東西。這個解決方案會是什麼?
您通過'args'(命令行參數)而不是STDIN(標準輸入)獲取參數。 – NullUserException