1 / 2
Feb 2019

Why am I getting a runtime error?
Thanks in advance!

import java.util.;
import java.lang.
;

class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);

	sc.nextInt();
	
	while(sc.hasNextInt()){
		
		int lowerBound = sc.nextInt();
		int upperBound = sc.nextInt();
		
		List<Integer> primes = new ArrayList<>();
		
		for(int i = lowerBound; i < upperBound ; i++){
			if( isPrime(i) ){ 
				primes.add(i); 
				
			}
		}
		
		for(int number: primes){
			System.out.println(number);
		}
	}
	
}

public static boolean isPrime(int number){
	for(int i = 0; i*i <= number; i++){
		if(number%i==0) return false;
	}
	return true;
}

}

  • created

    Feb '19
  • last reply

    Feb '19
  • 1

    reply

  • 814

    views

  • 2

    users

  • 1

    link

Take a close look.