Computer Science, asked by suman2911, 5 months ago

Accept a list from the user and display the sum of all the even numbers in the list. Check that the element is a number first before checking if the number is even.

Answers

Answered by harnathyadav2907
0

\huge\mathbb\pink{\underline {\underline{Answer}}}

import java.util.Scanner;

public class FiftyPrimes

{

// Return true if a number n is prime

public static boolean isPrime(long n)

{

// Check division from 2 to sqrt(n)

for (long i = 2; i <= Math.sqrt(n); i++)

{

if (n % i == 0)

{

return false;

}

}

// If no division is found, number is prime

return true;

}

public static void main(String[] args)

{

// Create Scanner object

Scanner sc = new Scanner(System.in);

// Take user input

System.out.print("Enter the starting point: ");

long start = sc.nextInt();

// Close Scanner object

sc.close();

// If start point is less than 2, make it 2

if (start < 2)

{

start = 2;

}

int numberOfPrimes = 0; // Number of primes printed

long number = start; // Number to be tested for prime

// Iterate until 50 primes are printed

while (numberOfPrimes < 50)

{

if (isPrime(number))

{

System.out.println(number);

numberOfPrimes++;

}

number++;

}

}

}

The manager of a company has a worksheet that contains an employee

The manager of a company has a worksheet that contains an employeelist along with their salary details. She wants to see only those employees

The manager of a company has a worksheet that contains an employeelist along with their salary details. She wants to see only those employeeswho get a salary above Rs. 5000.

\huge\mathtt\purple{THANK\:YOU}

Similar questions