Oto mój kod, co robię źle ?
public static boolean CzyPierwsza(int n)
{
if(n <=1)
{
return false;
}
else if(n == 2)
{
return true;
}
else if(n % 2 == 0)
{
return false;
}
for(int i=3; i <= Math.sqrt(n) ; i += 2)
{
if(n % i == 0)
{
return false;
}
}
return true;
}
public static void WypiszPierwsza(int m, int n)
{
for(int i = m; i <= n; i++)
{
if(CzyPierwsza(i) == true)
{
System.out.println(i);
}
}
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Scanner sc = new Scanner(System.in);
int [] Liczby = new int [2];
int [][] Tablica;
int test_c;
String l;
test_c = sc.nextInt();
Tablica = new int [2][test_c];
for(int i=0; i< test_c; i++)
{
l = br.readLine();
String [] tab = l.trim().split("\\s+");
for(int k=0; k<Liczby.length; k++)
{
Liczby[k] = Integer.parseInt(tab[k]);
Tablica[k][i] = Liczby[k];
}
}
for(int p=0; p<test_c; p++)
{
WypiszPierwsza(Tablica[0][p], Tablica[1][p]);
System.out.println();
}
}
created
last reply
- 5
replies
- 452
views
- 3
users
- 1
like
- 1
link