1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Orlov [11]
3 years ago
12

Sum of Primes JAVA project

Computers and Technology
1 answer:
vitfil [10]3 years ago
4 0

Answer:

Explanation:

The following code is written in Java and creates the necessary code so that two int inputs are read and looped through all the numbers between them to find all the primes. These primes are counted and summed. Finally, printing out the sum and the number of primes found to the console.

import java.util.ArrayList;

import java.util.Scanner;

class SumPrimes{

   public static void main(final String[] args) {

       Scanner in = new Scanner(System.in);

           ArrayList<Integer> primes = new ArrayList<>();

           int num1, num2, numPrime = 0;

           System.out.println("Enter number 1:");

           num1 = in.nextInt();

           System.out.println("Enter number 2:");

           num2 = in.nextInt();

           for (int x = num1; x <= num2; x++) {

               if (isPrime(x) == true) {

                   primes.add(x);

                   numPrime += 1;

               }

           }

           System.out.println("There are " + numPrime + " primes in the array.");

       System.out.println("Their sum is " + sumArray(primes));

}

   public static int sumArray(ArrayList<Integer> arr) {

       int sum = 0;

       for (int x: arr) {

           sum += x;

       }

       return sum;

   }

   static boolean isPrime(int n) {

       if (n <= 1)

           return false;

       for (int i = 2; i < n; i++)

           if (n % i == 0)

               return false;

       return true;

   }

}

You might be interested in
What is an umbrella of software programs that may include​ CAD/CAM, product​ routing, maintenance, and other product​ concerns?
Andrew [12]

Answer:

Product lifecycle management software

Explanation:

Characteristics.

  • Complete set of tools to establish decision criteria regarding the portfolio and simulations for  product planning.
  • It allows the standardization and automation of the processes of request of alterations in the product, controlling the  decisions, deadlines and ensuring traceability.
  • Improves efficiency in product design.
  • <em>Example SoftExpert PLM </em>is an accessible, easy-to-use and completely web solution for managing the life cycle of  products.
6 0
4 years ago
Which of these devices can completely stop broadcasts from being passed on across the network? routerswitchaccess ponthub
cestrela7 [59]

Answer

An Access point can completely stop broadcasts from being passed on across the network.

Explanation.

An Access point is a hardware type that is part of local area network which has capability of allowing wireless communication from devices through a wireless stand,which connects in between devices and the network. A good example of these devices are routers that allows wireless devices to connect to a wireless network.So when it is passed on across a network an Access point can completely stop.

8 0
3 years ago
Read 2 more answers
If you fail a course as a MAIN (residency) course, you can repeat that course as either a MAIN (residency) or an online (IG or I
Elina [12.6K]

Answer: False

Explanation:

The statement that "you fail a course as a MAIN (residency) course, you can repeat that course as either a MAIN (residency) or an online (IG or IIG) course" is false.

It should be noted that if one fail a course as a residency course, the course can only be repeated as a main (residency) course and not an online course. When a course is failed, such course has to be repeated the following semester and this will give the person the chance to improve their GPA.

5 0
3 years ago
What is the impact of Customer Centricity?
skad [1K]
Customer-centric businesses generate greater profits, increased employee engagement, and more satisfied customers. Customer-centric governments and nonprofits create the resiliency, sustainability, and alignment needed to fulfill their mission.
5 0
2 years ago
Write a function called reverse() with this prototype:
tresset_1 [31]

Answer:

void reverse(char dest[], char source[], int size)

{

   for(int i=0;i<size;i++)//using for loop.

   {

       dest[i]=source[i];//assigning each element of source array to dest array.

   }

   int s=0,e=size-1;//initializing two elements s with 0 and e with size -1.

   while(s<e){

       char t=des[s];             //SWAPPING

       dest[s]=dest[e];            //SWAPPING

       dest[e]=t;                  //SWAPPING

       s++;

       e--;

   }

}

Explanation:

I have used while loop to reverse the array.I have initialize two integer variables s and e with 0 and size-1.Looping until s becomes greater than e.

It will work as follows:

first s=0 and e=0.

dest[0] will be swapped with dest[size-1]

then s=1 and e=size-2.

then des[1] will be swapped with dest[size-2]

and it will keep on going till s is less than e.

4 0
3 years ago
Other questions:
  • What is the difference between a fiber optic cable and a twisted pair cable?
    5·1 answer
  • With respect to the five components of social media information systems (SMIS), which of the following statements is true of SM
    11·1 answer
  • Who designed the apple i computer in 1976?
    7·2 answers
  • You want to save twenty of your vacation pictures on your computer. Which is the best place to save them?
    6·2 answers
  • PLEASE HURRYYY Suppose your employer wants you to purchase a tablet device that you will use to run the company's custom sales s
    15·2 answers
  • The intuitive interface designed by alan kay is called a ________.
    11·1 answer
  • What is being identified when antibodies stick to pathogens during immunostaining?
    11·1 answer
  • A External hackers have some access to a company's website and made some changes. Customers have submitted multiple complaints v
    11·1 answer
  • What can relaxation help to reduce?
    14·1 answer
  • Where does Reiner take eren after they have a fight?
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!