We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ac84c2d commit 8cc766fCopy full SHA for 8cc766f
JavaArray02.txt
@@ -0,0 +1,28 @@
1
+/*Write a java program that takes 2 integer numbers as input and calculates how many prime numbers exist between them.*/
2
+
3
+import java.util.Scanner;
4
+ public class Task02{
5
+ public static void main(String[]args){
6
+ Scanner sc=new Scanner(System.in);
7
+ int n1= sc.nextInt();
8
+ int n2=sc.nextInt();
9
+ int count=0;
10
+ if(n1<n2){
11
+ for(int i=n1;i<=n2;i++){
12
+ int div=0;
13
+ for(int j=2;j<=i/2;j++){
14
+ if(i%j==0){
15
+ div++;}}
16
+ if(div==0){
17
+ count++;}}}
18
+ else{
19
+ for(int i=n2;i<=n1;i++){
20
21
22
23
24
25
26
+ System.out.println("There are "+count+" prime numbers between "+ n1+" and "+n2);
27
+ }
28
0 commit comments