primes - Java: RuntimeException when run on spoj.com -
The prime number generator is the question for the problem (from spoj.com):
Peter wants his Generate some key numbers for the crypto system, help it! Your task is to generate all the major numbers between the two given numbers!
Input:
The input starts with the number of test cases in the same line (t
Output:
Print all the major numbers for each exam, such as m & lt; = P & lt; = N, one number per line, the test lines are divided by an empty line.
Example:
Input:
2 1 10 3 5 Output:
2 3 5 7 3 5 My code for:
Package competitive code; Import java.util.Scanner; Class problem 2 {public static zero main (string agre []) {scanner sc = new scanner (System.in); Scanner st = new scanner (System.in); Int t = sc.nextInt (); // Input "number" lines that user int, a, b, flag, count; String line [] = new string [t]; String [] number = new string [2]; For (int i = 0; i count; ++) {number = line [count] .split (""); A = integer. Press (number [0]); B = integer ParisInt (number [1]); For {int i = a; i and lt; = b; i ++} {for (jit j = 2; j and lt; = i; j ++) {if (i% j == 0) { If (i == j) System.out .println (i); And break; }}} System.out.println (); }}} Error: The submitted code produces runtime expansions at spoj.com, though it works perfectly fine on my system is.
always exception can be handled (ideal By way, an extraordinary behavior you can recover from, adding an Oracle document for the exception) and never consider user input secure:
BufferedReader Br = new BufferedReader (new InputStreamReader (System.in)); Int t = 2; Try each line * / / (int i = 0; i & lt; i ++) {/ * line * / string line = br.readLine (); / * Divide the line / string [] numbers = line.split (""); If (numbers.length! = 2) throw the new ArrayIndexOutOfBoundsException (); / * Parse value * / int min = integer Parasont (number [0]); Int max = integer Parasont (number [1]); / * Your Check * / __find_prime_numbers__}} Catch (Number Format Expretion) {/ * Notice to User - & gt; The input format is not correct, for example: "1m" * /} cache (prior to exchanged exposure before) {/ * User notice - & gt; Input format is not correct, for example: "1" or "1 2 3" * /}
Comments
Post a Comment