rime number is a number which is not divided by other number without 1and that number.
Here , we decided that we consider the first number and last number then in this number range prnt the prime number.
Source Code:
- public class PrimeNo1 {
- public static void main(String[] args) {
- try (Scanner input = new Scanner(System.in)) {
- int i,j,count = 0,totalprime = 0;
- System.out.println("Enter the first number:");
- int num1 =input.nextInt();
- System.out.println("Enter the end number:");
- int num2 = input.nextInt();
- System.out.println("prime numbers are :");
- for(i=num1;i<=num2;i++) {
- for(j=2;j<i;j++) {
- if(i%j==0) {
- count++;
- break;
- }
- }
- if(count==0) {
- System.out.print(i+" ");
- totalprime++;
- }
- count = 0;
- }
- System.out.println();
- System.out.println("Total Number of Prime Numbers are = "+totalprime);
- }
- }
- }
Output:
Enter the first number:5Enter the end number:50prime numbers are :5 7 11 13 17 19 23 29 31 37 41 43 47Total Number of Prime Numbers are = 13
0 comments:
Post a Comment