Hi all,
Need some help with this problem, I submitted two different solutions using different i/o techniques
import java.io.*;
import java.util.*;
public class Main
{
public static void main (String [] args) throws IOException
{
BufferedReader input = new BufferedReader (new InputStreamReader (System.in));
String n = input.readLine();
StringTokenizer tok = new StringTokenizer(n," \n");
int n1 = Integer.parseInt(tok.nextToken());
int n2 = Integer.parseInt(tok.nextToken());
int ans = 0;
int count = 0;
while(count <n1)
{
String t = input.readLine();
int t1 = Integer.parseInt(t);
if(t1 % n2 == 0)
ans++;
count ++;
}
System.out.println(ans);
input.close();
}
}
Im getting a "runtime error (NZEC)", can anybody suggest advise. The other solution used the Scanner Class instead of Java IO, and that time I obtained "time limit exceeded" - Note the reason for using the StringTokenizer is to be able to read the two seperate numbers "n" and "k" due to the "readLine()", with the Scanner Class i simply used ".nextInt()" and hence there was no need for a StringTokenizer. Is the Scanner Class slow?
Thanks