Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

print all prime no java

import java.util.Scanner;

public class SumOfPrimeNo {
    public static void main(String[] args) {

        int temp, no,sum=0,count=0,loop1=0,loop2=0;;
        System.out.println("--The sum of the All prime Number in Between 2 to ??--");

        Scanner sc = new Scanner(System.in);
        System.out.println("Enter a Number ");
        no = sc.nextInt();

       for (int j = 2; j <= no; j++)
       {
            loop1++;
              temp=0;

           for (int i = 2; i <= j/2; i++) {
                 loop2++;
               if (j % i == 0) {
                   temp=1;
                   break;
               }

           }
           if (temp==0) {
               System.out.print(j+"	");
               count++;
               sum=sum+j;
           }


       }

        System.out.println("
The Total no of Prime Number between 1 to "+no+" is = "+count);
        System.out.println("The sum of all Prime Numbers in between 1 to "+no+" is = "+sum);

        System.out.println("How many times Loop ran = "+(loop1+loop2)+" times,"+" loop1 = "+loop1+" times, "+"loop2 = "+loop2+" times");


    }}
Comment

PREVIOUS NEXT
Code Example
Java :: instance block in java 
Java :: POM error: Failure to find org.springframework.boot 
Java :: Java Using of() Method 
Java :: Marging ViewPager 
Java :: view binding 
Java :: Note: flutterpluginspathproviderPathProviderPlugin.java uses unchecked or unsafe operations. 
Java :: java bitwise xor 
Java :: sha-1 key generator 
Java :: expression régulière seulement un espace java 
Java :: trier un tableau de string java 
Java :: android how to get month on world programmatically 
Java :: managa firebase users 
Java :: what is difference between constant and final in java 
Java :: convert array to phone number java 
Java :: cfgbcfdxv 
Java :: regex pattern to mathc IP address 
Java :: difference between compile and execute in java 
Java :: code to close dialog containg layout 
Java :: copy one string to another without using any loops or assignment operator 
Java :: re-loop after last item in array java 
Java :: how to find a specific character in a string using array 
Java :: Java Create a FileOutputStream 
Java :: how to create 2d arrazlist in java 
Java :: bigint is built in object 
Java :: why fields should be final in immutable class? 
Java :: replace string placeholder java 
Java :: manifest merger 
Java :: how to stop spring boot application 
Java :: java initialize dynamic array of boolean 
Java :: super class and concrete class in java 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =